Make the plot not hit the 'ceiling'

5 views (last 30 days)
JP
JP on 12 Apr 2022
Commented: JP on 12 Apr 2022
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.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Apr 2022
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 Comment
JP
JP on 12 Apr 2022
Thank you very much! This worked perfectly!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!