Make the plot not hit the 'ceiling'

5 ビュー (過去 30 日間)
JP
JP 2022 年 4 月 12 日
コメント済み: JP 2022 年 4 月 12 日
So, in the graph that I attached, the line for the upper graph, for some reason is hidden in the 0.1 axis. If I stretch my eyes, I can see the blue slit. However, it makes it very hard to indentify it. I was wondering if there is a way to prop the axis up.
Note however, that this is runnin in a loop, so every graph have different boundaries. Thus I cant set a fixed limit for them.

採用された回答

Walter Roberson
Walter Roberson 2022 年 4 月 12 日
In the general form where you might have a number of different objects plotted in the same axes, and the data is not necessarily starting from zero.
factor = 1/20;
ax = gca();
all_y = {findobj(ax, '-property', 'YData').YData};
maxy = max(cellfun(@max, all_y));
miny = min(cellfun(@min, all_y));
dylim = (maxy - miny)*factor
ylim( [miny - dylim, maxy + dylim]);
In practice a lot of the time this can be replaced entirely by something like
ylim([0 max(y)*1.05])
where y is your vector of y values when you drew a single line using plot(x,y)
Note: the above code will fail if the data contains infinite values.
  1 件のコメント
JP
JP 2022 年 4 月 12 日
Thank you very much! This worked perfectly!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by