Set or query x-axis tick values (2024)

Set or query x-axis tick values

collapse all in page

Syntax

xticks(ticks)

xt = xticks

xticks('auto')

xticks('manual')

m = xticks('mode')

___ = xticks(ax,___)

Description

example

xticks(ticks) setsthe x-axis tick values, which are the locations alongthe x-axis where the tick marks appear. Specify ticks asa vector of increasing values; for example, [0 2 4 6].This command affects the current axes.

xt = xticks returnsthe current x-axis tick values as a vector.

example

xticks('auto') sets an automatic mode,enabling the axes to determine the x-axis tickvalues. Use this option if you change the tick values and then wantto set them back to the default values.

xticks('manual') sets a manual mode, freezingthe x-axis tick values at the current values.Use this option if you want to retain the current tick values whenresizing the axes or adding new data to the axes.

m = xticks('mode') returnsthe current x-axis tick values mode, which iseither 'auto' or 'manual'. Bydefault, the mode is automatic unless you specify tick values or changethe mode to manual.

example

___ = xticks(ax,___) usesthe axes specified by ax instead of the currentaxes. Specify ax as the first input argument forany of the previous syntaxes.

Examples

collapse all

Specify x-Axis Tick Values and Labels

Open Live Script

Create a line plot. Display tick marks along the x-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'})

Set or query x-axis tick values (1)

Specify Nonuniform x-Axis Tick Values

Display tick marks along the x-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])

Set or query x-axis tick values (2)

Increment x-Axis Tick Values by 10

Open Live Script

Display tick marks along the x-axis at increments of 10, starting from 0 and ending at 50.

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

Set or query x-axis tick values (3)

Increment x-Axis Tick Values by Pi

Open Live Script

Create a line plot. Specify the x-axis limits as 0 to 6π. Then, display tick marks along the x-axis at increments of π.

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

Set or query x-axis tick values (4)

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

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

Set or query x-axis tick values (5)

Change Tick Values for x-Axis with Durations

Open Live Script

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

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

Set or query x-axis tick values (6)

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

Set or query x-axis tick values (7)

Set x-Axis Tick Values Back to Default Values

Open Live Script

Create a stem chart and specify the x-axis tick values. Then, set the x-axis tick values back to the default values.

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

Set or query x-axis tick values (8)

xticks('auto')

Set or query x-axis tick values (9)

Specify x-Axis Tick Values for Specific Axes

Open Live Script

Starting in R2019b, you can display a tiling of plots using the tiledlayout and nexttile functions. Call the tiledlayout function to create a 2-by-1 tiled chart layout. Call the nexttile function to create the axes objects ax1 and ax2. Plot random data into each axes. Then set the x-axis tick values for the lower plot by passing ax2 as the first input argument to the xticks function.

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

Set or query x-axis tick values (10)

Remove x-Axis Tick Marks

Open Live Script

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

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

Set or query x-axis tick values (11)

Input Arguments

collapse all

ticksTick values
vector of increasing values

Tick values,specified as a vector of increasing values. If you do not want tickmarks along the x-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 mustmatch the type of values along the x-axis.

Example: xticks([pi 2*pi 3*pi 4*pi])

Example: xticks(0:10:100)

Example: xticks([])

Note

To specify the tick labels, use the xticklabels function.

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

axTarget axes
Axes object | array of Axes objects

Target axes, specified as an Axes object or an array of Axes objects.

If you do not specify this argument, then xticks modifies the current axes.

Output Arguments

collapse all

xt — Current tick values
vector

Current tick values, returned as a vector.

m — Current mode
'auto' | 'manual'

Current mode, returned as one of these values:

  • 'auto' — Automatically determinethe x-axis tick values.

  • 'manual' — Use manuallyspecified x-axis tick values.

More About

collapse all

Tick Values

The tick values are the locations along the x-axis where the tick marks appear. The tick labels are the labels that you see for each tick mark. Set the values using the xticks function. Set the corresponding labels using the xticklabels function.

Set or query x-axis tick values (12)

Algorithms

The xticks function sets and queries severalaxes properties related to the x-axis tick values.

  • XTick — Property that stores the x-axistick values.

  • XTickMode — Property that storesthe x-axis tick value mode. When you set the x-axistick values, this property changes to 'manual'.

Version History

Introduced in R2016b

See Also

Functions

  • yticks | zticks | xtickformat | xticklabels | xtickangle | xlim

Properties

  • Axes Properties

Topics

  • Specify Axis Tick Values and Labels

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Set or query x-axis tick values (13)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

Contact your local office

Set or query x-axis tick values (2024)
Top Articles
Latest Posts
Article information

Author: Reed Wilderman

Last Updated:

Views: 6008

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Reed Wilderman

Birthday: 1992-06-14

Address: 998 Estell Village, Lake Oscarberg, SD 48713-6877

Phone: +21813267449721

Job: Technology Engineer

Hobby: Swimming, Do it yourself, Beekeeping, Lapidary, Cosplaying, Hiking, Graffiti

Introduction: My name is Reed Wilderman, I am a faithful, bright, lucky, adventurous, lively, rich, vast person who loves writing and wants to share my knowledge and understanding with you.