How can I start my axis from 0 but keep the max limit automatic?

y-axis of my plot starts from negavite values but I want it to start from zero. I can not know the max value until I execute the code. Since I will be using the code for many data, I have tried to use ylim, v= axis...Thank you in advance for your help

 Accepted Answer

ylim([0 inf])

3 Comments

Thanks :) I was putting a comma between them so it wasn't working
It's a good solution, just note that it overrides your YLimitMethod, making it effectively "tight", even if you want it to be e.g. "tickaligned", meaning your upper limit will be the maximal datapoint, not the next tick value.
In my opinion this is something Mathworks should fix, allowing to force axes to include zero without it affecting the YLimitMethod. It can also be flexible enough to dynamically cover the case where zero is not the smallest value.

Sign in to comment.

More Answers (1)

Probably not the neatest solution ( Azzi Abdelmalek's solution is better! ), but you could just use the auto limits each time you update/refrseh your plot, then immediately afterwards set the lower x limit to 0.
e.g.
ylims = get( hAxes, 'Ylim' )
ylims(1) = 0;
set( hAxes, 'Ylim', ylims )

Categories

Products

Tags

Asked:

G
G
on 15 Aug 2014

Edited:

on 30 Jul 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!