About Ylim

14 ビュー (過去 30 日間)
Lara
Lara 2011 年 11 月 7 日
コメント済み: Marcel 2021 年 9 月 16 日
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

回答 (3 件)

Jan
Jan 2011 年 11 月 7 日
set(gca, 'YLim', [0, inf]);
Then Matlab uses the hard coded lower limit 0 and the upper limit from the drawn data.
  3 件のコメント
Jan
Jan 2011 年 11 月 7 日
@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
Marcel 2021 年 9 月 16 日
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
Daniel Shub 2011 年 11 月 7 日
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)])]);

Grzegorz Knor
Grzegorz Knor 2011 年 11 月 7 日
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)])

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by