# yticklabels

Set or query y-axis tick labels

## Syntax

yticklabels(labels)
yl = yticklabels
yticklabels('auto')
yticklabels('manual')
m = yticklabels('mode')
___ = yticklabels(ax,___)

## Description

example

yticklabels(labels) sets the y-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 y-axis tick values and tick labels no longer update automatically based on changes to the axes.
yl = yticklabels returns the y-axis tick labels for the current axes.

example

yticklabels('auto') sets an automatic mode, enabling the axes to determine the y-axis tick labels. Use this option if you set the labels and then want to set them back to the default values.
yticklabels('manual') sets a manual mode, freezing the y-axis tick labels at the current values.
m = yticklabels('mode') returns the current value of the y-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.

example

___ = yticklabels(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.

## Examples

collapse all

Create a line plot. Display tick marks along the y-axis at the values 0, 50, and 100. Then, specify a label for each tick mark.

x = linspace(0,10); y = x.^2; plot(x,y) yticks([0 50 100]) yticklabels({'y = 0','y = 50','y = 100'})

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 plots of random data. Set the y-axis tick values and labels for the second plot by passing ax2 as the first input argument to the yticks and yticklabels functions.

tiledlayout(2,1) ax1 = nexttile; plot(rand(3)) ax2 = nexttile; plot(rand(3)) yticks(ax2,[0 .25 .5 .75 1]) yticklabels(ax2,{'y = 0','1/4','1/2','3/4','y = 1'})

Create a stem chart and specify the y-axis tick values and corresponding labels. Then, set the y-axis tick values and labels back to the default values.

stem(1:10) yticks([1 4 6 10]) yticklabels({'A','B','C','D'})

yticks('auto') yticklabels('auto')

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

plot(rand(5)) yticklabels({})

## 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: yticklabels({'0','\pi','2\pi'})

Example: yticklabels({'January','Febrary','March'})

Example: yticklabels({})

### Note

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

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

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

If you do not specify this argument, then yticklabels 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 y-axis tick labels.

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

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 y-axis where the tick marks appear. Set the tick values using the yticks function. Set the corresponding tick labels using the yticklabels function.

## Algorithms

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

• YTickLabel — Property that stores the text for the y-axis tick labels.

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

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