xtickformat
Gets or sets the number format of the x-axis tick labels.
Category: Graphics > Formatting and Annotation
Syntax
xtickformat(fmt)
Formats the tick labels with fmt, a sprintf-style specification such as '%.1f', or a name like 'usd'.
f = xtickformat
Returns the current format.
xtickformat(ax, ___)
Acts on the axes ax.
Description
The format controls how the numbers at the ticks are written, without changing where the ticks are. Adding a unit ('%d%%') or fixing the number of decimals avoids labels such as 0.30000000004.
If the labels were set by hand with xticklabels, the format has no visible effect until xticklabels('auto') is called.
Input arguments
fmt- Text such as
'%d%%'or'%.2f', or'usd','eur'for currency. For datetime axes it is a datetime format such as'MMM dd'.
Output arguments
f- Current format as text.
Example
Percent labels
plot(0:10:100, (0:10).^2)
xtickformat('%d%%')
f = xtickformat
xticklabels
Output
f = '%d%%'
ans = 6×1 cell
{'0%' }
{'20%' }
{'40%' }
{'60%' }
{'80%' }
{'100%'}