Documentation Center

  • Trial Software
  • Product Updates

ylim

Set or query y-axis limits

Syntax

ylim
ylim([ymin ymax])
ylim('mode')
ylim('auto')
ylim('manual')
ylim(axes_handle,...)

Description

ylim with no arguments returns the limits of the current axes.

ylim([ymin ymax]) sets the axis limits in the current axes to the specified values.

ylim('mode') returns the current value of the axis limits mode, which can be either auto (the default) or manual.

ylim('auto') sets the axis limit mode to auto.

ylim('manual') sets the axis limit mode to manual.

ylim(axes_handle,...) performs the set or query on the axes identified by the first argument, axes_handle. When you do not specify an axes handle, it operates on the current axes.

Examples

expand all

Specify Axis Limits

Set the x-axis and y-axis limits to match the range of data.

[x,y] = meshgrid(-1.75:.2:3.25);
z = x.*exp(-x.^2-y.^2);

figure
surf(x,y,z)
xlim([-1.75,3.25])
ylim([-1.75,3.25])

Alternatives

To control the upper and lower axis limits on a graph, use the Property Editor, one of the plotting tools . For details, see The Property Editor.

More About

expand all

Tips

ylim sets or queries values of the axes object YLimand YLimMode property.

When the axis limit mode is set to auto (the default), MATLAB® uses limits, which are round numbers, to span the range of the data being displayed. Setting a value for any of the limits also sets the corresponding mode to manual. If you set the limits on an existing graph and want to maintain these limits while adding more graphs, use the hold command.

    Note:   High-level plotting functions like plot and surf reset both the modes and the limits.

See Also

| |

Was this topic helpful?