About Ylim
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everyone ! I want to plot a curve with positive and negative values on the Y-axis. I want to limit the figure to positive values so Ylim starts from 0, but I also want the high limit to be in mode auto. Is there a way to do so ? Thanks for your replies
0 Commenti
Risposte (3)
Jan
il 7 Nov 2011
set(gca, 'YLim', [0, inf]);
Then Matlab uses the hard coded lower limit 0 and the upper limit from the drawn data.
3 Commenti
Jan
il 7 Nov 2011
@Daniel: Correct. Using Grzegorz' method considers the autoscaling. But the auto-scaling is affected by setting the lower limit recursively, see:
x = rand(1, 100) - 0.9; subplot(1,2,1); plot(x); subplot(1,2,2); plot(max(0, x));
Is there a public description of the auto-limit algorithm?
Marcel
il 16 Set 2021
is there any new knowledge about the question, how the auto-limit algorithm looks like?
for performance reasons I try to avoid the "auto" mode, I believe a self coded function can be way faster... THANKS
Daniel Shub
il 7 Nov 2011
I set the YLimMode to auto in case you have already specified a ylim value. If the max of ylim is less than 0, you need to set the ylim to something else (in this case [0, 1]).
set(gca, 'YLimMode', 'Auto');
set(gca, 'YLim', [0, max([1, max(ylim)])]);
0 Commenti
Grzegorz Knor
il 7 Nov 2011
Get ylim value from current axis, and then set limit from zero to maximum (second) value:
plot(randn(1000,1))
yl = get(gca,'ylim');
ylim([0 yl(2)])
0 Commenti
Vedere anche
Categorie
Scopri di più su Subplots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!