Documentation

xticks

Set or queryx设在蜱虫值

Syntax

xticks(ticks)
xt = xticks
xticks('auto')
xticks('manual')
m = xticks('mode')
___= xticks(ax,___)

Description

example

xticks(ticks)sets thex-axistick values, which are the locations along thex-axis where the tick marks appear. Specifyticksas a vector of increasing values; for example,[0 2 4 6]. This command affects the current axes.

xt= xticksreturns the currentx设在蜱虫值as a vector.

example

xticks('auto')sets an automatic mode, enabling the axes to determine thex设在蜱虫值. Use this option if you change the tick values and then want to set them back to the default values.

xticks('manual')sets a manual mode, freezing thex设在蜱虫值at the current values. Use this option if you want to retain the current tick values when resizing the axes or adding new data to the axes.

m= xticks('mode')returns the currentx设在蜱虫值mode, which is either'auto'or'manual'. By default, the mode is automatic unless you specify tick values or change the mode to manual.

example

___= xticks(ax,___)uses the axes specified byaxinstead of the current axes. Specifyaxas the first input argument for any of the previous syntaxes.

Examples

collapse all

Create a line plot. Display tick marks along thex-axis at the values 0, 5, and 10. Then specify a label for each tick mark.

x = linspace(0,10); y = x.^2; plot(x,y) xticks([0 5 10]) xticklabels({'x = 0','x = 5','x = 10'})

Display tick marks along thex-axis at nonuniform values between -5 and 5. MATLAB® labels the tick marks with the numeric values.

x = linspace(-5,5); y = x.^2; plot(x,y) xticks([-5 -2.5 -1 0 1 2.5 5])

Display tick marks along thex设在的增量10, starting from 0 and ending at 50.

x = linspace(0,50); y = sin(x/2); plot(x,y) xticks(0:10:50)

Create a line plot. Specify thex-axis limits as 0 to. Then, display tick marks along thex设在的增量.

x = linspace(0,6*pi); y = sin(x); plot(x,y) xlim([0 6*pi]) xticks(0:pi:6*pi)

MATLAB® labels the tick marks with the numeric values. Change the labels to show thesymbol by specifying the text for each label.

xticklabels({'0','\pi','2\pi','3\pi','4\pi','5\pi','6\pi'})

Create a plot with duration values along thex-axis. Then, change the duration values where the tick marks are located.

t = minutes(0:.5:3); y = rand(1,7); plot(t,y)

ticks = minutes(0:.25:3); xticks(ticks)

Create a stem chart and specify thex设在蜱虫值. Then, set thex设在蜱虫值back to the default values.

stem(1:10) xticks([0 4 6 10])

xticks('auto')

Create a figure with two subplots and return the axes objects asax1andax2. Plot random data in each subplot. Set thex设在蜱虫值for the lower subplot by passingax2as the first input argument to thexticksfunction.

ax1 = subplot(2,1,1); plot(rand(3)) ax2 = subplot(2,1,2); plot(rand(3)) xticks(ax2,[1 2 3])

Remove the tick marks along thex-axis by specifying the tick values as an empty array.

x = linspace(0,10); y = sin(x); plot(x,y) xticks([])

Input Arguments

collapse all

Tick values, specified as a vector of increasing values. If you do not want tick marks along thex-axis, specify an empty vector[].

You can specify the tick values as numeric, categorical, datetime, or duration values. However, the type of values that you specify must match the type of values along thex-axis.

例子:xticks([pi 2*pi 3*pi 4*pi])

例子:xticks(0:10:100)

例子:xticks([])

Note

To specify the tick labels, use thexticklabelsfunction.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64|categorical|datetime|duration

Target axes, specified as a singleAxesobject or a vector ofAxes对象。如果你不specify the axes, thenxticksuses the current axes.

Output Arguments

collapse all

Current tick values, returned as a vector.

Current mode, returned as one of these values:

  • 'auto'— Automatically determine thex设在蜱虫值.

  • 'manual'— Use manually specifiedx设在蜱虫值.

More About

collapse all

Tick Values

The tick values are the locations along thex-axis where the tick marks appear. The tick labels are the labels that you see next to each tick mark. Set the values using thexticksfunction. Set the corresponding labels using thexticklabelsfunction.

Algorithms

Thexticksfunction sets and queries several axes properties related to thex设在蜱虫值.

  • XTick— Property that stores thex设在蜱虫值.

  • XTickMode— Property that stores thex-axis tick value mode. When you set thex设在蜱虫值, this property changes to'manual'.

Introduced in R2016b

Was this topic helpful?