yticklabels

Gets or sets the text of the y-axis tick labels.

Category: Graphics > Formatting and Annotation

Syntax

yticklabels(labels)

Sets the labels, a cell array or string array with one entry per tick.

lbl = yticklabels

Returns the current labels as a cell array.

yticklabels('auto')

Goes back to automatically generated labels.

yticklabels(ax, ___)

Acts on the axes ax.

Description

Labels are matched to the ticks given by yticks, so set the tick positions first. Replacing the numbers by names is the main use, for example weekdays or categories on a bar chart.

The labels live in the YTickLabel property of the axes. Setting them by hand switches YTickLabelMode to manual.

Input arguments

labels
Text for each tick, in order. If there are fewer labels than ticks, they repeat.

Output arguments

lbl
Cell array with the current labels.

Example

Names instead of numbers

barh([4 7 3])
yticks(1:3)
yticklabels({'low', 'mid', 'high'})
yticklabels
Output
ans = 3×1 cell

    {'low' }
    {'mid' }
    {'high'}

See also

yticks xticklabels ytickangle ytickformat ylim