About Ylim
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
Jan
am 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 Kommentare
Jan
am 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
am 16 Sep. 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
am 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 Kommentare
Grzegorz Knor
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Subplots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!