xticks
Gets or sets the positions of the x-axis tick marks.
Category: Graphics > Formatting and Annotation
Syntax
xticks(ticks)
Sets the tick positions to the values in the vector ticks.
t = xticks
Returns the current tick positions.
xticks('auto')
Goes back to automatic tick placement.
xticks(ax, ___)
Acts on the axes ax.
Description
By default the axes choose round tick values that depend on the limits. xticks fixes them instead, which is useful to mark the points where data were sampled or the multiples of pi on a trigonometric plot. The positions are stored in the XTick property.
Pair it with xticklabels to give the ticks custom text.
Input arguments
ticks- Vector of increasing values. An empty vector
[]removes the ticks.
Output arguments
t- Row vector with the current tick positions.
Example
Ticks at multiples of pi/2
x = linspace(0, 2*pi, 100);
plot(x, sin(x))
xticks(0:pi/2:2*pi)
xticklabels({'0', '\pi/2', '\pi', '3\pi/2', '2\pi'})
t = xticks
Output
t = 1×5
0 1.5708 3.1416 4.7124 6.2832