ylim
Gets or sets the limits of the y-axis.
Category: Graphics > Formatting and Annotation
Syntax
ylim([ymin ymax])
Sets the limits of the current axes.
yl = ylim
Returns the current limits as a two-element vector.
ylim('auto')
Lets the axes choose limits that fit the data again.
ylim(ax, ___)
Acts on the axes ax.
Description
The limits decide which part of the data is visible. Data outside the range is clipped, not removed. Setting limits turns off automatic fitting for that axis until ylim('auto') is called.
The limits are stored in the YLim property of the axes. To flip the direction of the axis, set ax.YDir = 'reverse'; the default for plots is 'normal', with values increasing upward.
Input arguments
[ymin ymax]- Two numbers with
ymin < ymax.-InfandInfare allowed and mean "fit the data on that side".
Output arguments
xl- Current limits,
[ymin ymax].
Example
Fix the vertical range
x = linspace(0, 10, 200);
plot(x, sin(x))
ylim([-2 2])
yl = ylim
Output
yl = 1×2
-2 2