xticklabels
Gets or sets the text of the x-axis tick labels.
Category: Graphics > Formatting and Annotation
Syntax
xticklabels(labels)
Sets the labels, a cell array or string array with one entry per tick.
lbl = xticklabels
Returns the current labels as a cell array.
xticklabels('auto')
Goes back to automatically generated labels.
xticklabels(ax, ___)
Acts on the axes ax.
Description
Labels are matched to the ticks given by xticks, 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 XTickLabel property of the axes. Setting them by hand switches XTickLabelMode 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
bar([4 7 3])
xticks(1:3)
xticklabels({'low', 'mid', 'high'})
xticklabels
Output
ans = 3×1 cell
{'low' }
{'mid' }
{'high'}