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 CenterFile Exchange에서 2-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