Make the plot not hit the 'ceiling'

5 Ansichten (letzte 30 Tage)
JP
JP am 12 Apr. 2022
Kommentiert: JP am 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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by