Main Content

zticklabels

Set or query z-axis tick labels

Description

zticklabels(labels) sets the z-axis tick labels for the current axes. Specify labels as a string array or a cell array of character vectors; for example, {'January','February','March'}. If you specify the labels, then the z-axis tick values and tick labels no longer update automatically based on changes to the axes.

example

zl = zticklabels returns the z-axis tick labels for the current axes.

zticklabels('auto') sets an automatic mode, enabling the axes to determine the z-axis tick labels. Use this option if you set the labels and then want to set them back to the default values.

example

zticklabels('manual') sets a manual mode, freezing the z-axis tick labels at the current values.

m = zticklabels('mode') returns the current value of the z-axis tick labels mode, which is either 'auto' or 'manual'. By default, the mode is automatic unless you specify the tick labels or set the mode to manual.

___ = zticklabels(ax,___) uses the axes specified by ax instead of the current axes. Specify ax as the first input argument for any of the previous syntaxes.

example

Examples

collapse all

Create a surface plot. Display tick marks along the z-axis at the values -8, 0, and 8. Then, specify a label for each tick mark.

[x,y,z] = peaks;
surf(x,y,z)
zticks([-8 0 8])
zticklabels({'z = -8','z = 0','z = 8'})

Figure contains an axes object. The axes object contains an object of type surface.

Starting in R2019b, you can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2. Create two 3-D stem plots. Set the z-axis tick values and labels for the first plot by passing ax1 as the first input argument to the zticks and zticklabels functions.

tiledlayout(2,1)
ax1 = nexttile;
stem3(ax1,4*rand(5))
zticks(ax1,[0 2 4])
zticklabels(ax1,{'z = 0','z = 2','z = 4'})

ax2 = nexttile;
stem3(ax2,4*rand(5))

Figure contains 2 axes objects. Axes object 1 contains an object of type stem. Axes object 2 contains an object of type stem.

Create a surface plot and specify the z-axis tick values and labels. Then, set the values and labels back to the default values.

[x,y,z] = peaks;
mesh(x,y,z)
zticks([-8 0 8])
zticklabels({'z = -8','z = 0','z = 8'})

Figure contains an axes object. The axes object contains an object of type surface.

zticks('auto')
zticklabels('auto')

Figure contains an axes object. The axes object contains an object of type surface.

Remove the tick labels along the z-axis by specifying the tick labels as an empty array.

[x,y,z] = peaks;
surf(x,y,z)
zticklabels({})

Figure contains an axes object. The axes object contains an object of type surface.

Input Arguments

collapse all

Tick labels, specified as a cell array of character vectors, string array, or categorical array. If you do not want tick labels to show, then specify an empty cell array {}. Tick labels support TeX and LaTeX markup. See the TickLabelInterpreter property of the Axes object for more information.

Example: zticklabels({'0','\pi','2\pi'})

Example: zticklabels({'January','February','March'})

Example: zticklabels({})

Note

  • To specify the tick values, use the zticks function.

  • If you do not specify enough labels for all the ticks values, MATLAB® uses the labels followed by empty character vectors for the remaining ticks.

  • If you specify the tick labels as a categorical array, MATLAB uses the values in the array, not the categories.

Target axes, specified as an Axes object or an array of Axes objects.

If you do not specify this argument, then zticklabels modifies the current axes.

Output Arguments

collapse all

Current tick labels, returned as a cell array of character vectors or a character array.

Current tick labels mode, returned as one of these values:

  • 'auto' — Automatically determine the z-axis tick labels.

  • 'manual' — Use manually specified z-axis tick labels.

More About

collapse all

Tick Labels

The tick labels are the labels that you see next to each tick mark. The tick values are the locations along the z-axis where the tick marks appear. Set the tick values using the zticks function. Set the corresponding tick labels using the zticklabels function.

Tick marks appear as short horizontal hashes along the z-axis. Tick labels for tick values appear as text directly to the left of each tick mark.

Algorithms

The zticklabels function sets and queries several axes properties related to the z-axis tick labels.

  • ZTickLabel — Property that stores the text for the z-axis tick labels.

  • ZTickLabelMode — Property that stores the z-axis tick label mode. When you set the z-axis tick labels using zticklabels, this property changes to 'manual'.

  • ZTickMode — Property that stores the z-axis tick value mode. When you set the z-axis tick labels using zticklabels, this property changes to 'manual'.

Version History

Introduced in R2016b