Set or query z-axis limits


  • zlim(limits)
  • zlim auto
  • zlim manual
  • zl = zlim
  • m = zlim('mode')
  • ___ = zlim(ax,___)


zlim(limits) sets the z-axis limits for the current axes. Specify limits as a two-element vector of the form [zmin zmax], where zmax is a numeric value greater than zmin.

zlim auto lets the axes choose the z-axis limits. The axes chooses limits that span the range of the plotted data. This command sets the ZLimMode property for the axes to 'auto'..

zlim manual freezes the limits at the current values. Use this option if you want to retain the current limits when adding new data to the axes using the hold on command. This command sets the ZLimMode property for the axes to 'manual'.

zl = zlim returns a two-element vector containing the current limits.

m = zlim('mode') returns the current value of the limits mode, which is either 'auto' or 'manual'. By default, the mode is automatic unless you specify limits or set the mode to manual.

___ = zlim(ax,___) uses the axes specified by ax instead of the current axes. The ax input argument can precede any of the input arguments in the previous syntaxes. Use single quotes around input arguments that are character strings, for example, zlim(ax,'auto') and zlim(ax,'manual'). You can include any of the output arguments in the preceding syntaxes if the original syntax supports an output argument.


collapse all

Set z-Axis Limits

Plot a surface and set the z-axis limits to range from -5 to 5.

[X,Y,Z] = peaks;
zlim([-5 5])

Set z-Axis Limits for Specific Axes

Create a figure with two subplots and plot the same data in each subplot. Set the z-axis limits for the bottom subplot.

[X,Y,Z] = peaks;
ax1 = subplot(2,1,1);

ax2 = subplot(2,1,2);
zlim(ax2,[-5 5])

Maintain Current z-Axis Limits

Use manual mode to maintain the current z-axis limits when you add more plots to the axes.

First, create a 3-D scatter plot.

theta = linspace(0,2*pi);
X = cos(theta);
Y = sin(theta);
Z = theta;

Set the z-axis limits mode to manual so that the limits to not change. Use hold on to add a second plot to the axes.

zlim manual
hold on
Znew = 5*theta;
hold off

The z-axis limits do not update to incorporate the new plot.

Switch back to automatically updated limits by setting the mode to automatic.

zlim auto

Return z-Axis Limits

Create a 3-D scatter plot of random data. Return the values of the z-axis limits.

x = randn(50,1);
y = randn(50,1);
z = randn(50,1);

zl = zlim
zl =

    -3     3

Input Arguments

collapse all

limits — Minimum and maximum limitstwo-element vector

Minimum and maximum limits, specified as a two-element vector of the form [zmin zmax]. Specifying the z-axis limits sets the z-axis limits mode to manual. The ZLim and ZLimMode properties for the corresponding axes store the z-axis limits and the limits mode, respectively.

Changing the z-axis limits can cause other limits to change, unless their corresponding mode properties are set to manual.

Example: [0 1]

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

ax — Axes objectaxes object

Axes object. If you do not specify an axes, then zlim sets the limits for the current axes (gca).

Output Arguments

collapse all

zl — Current limitstwo-element vector

Current limits, returned as a two-element vector of the form [zmin zmax].

Querying the limits returns the ZLim property value for the corresponding axes.

m — Current limits mode'auto' | 'manual'

Current limits mode, returned as one of these values:

  • 'auto' — The limits update to reflect changes in the data.

  • 'manual' — The limits do not update to reflect changes in the data.

Querying the z-axis limits mode returns ZLimMode property value for the corresponding axes.

See Also

| | | | |

Introduced before R2006a

Was this topic helpful?