Set or query x-axis tick labels (2024)

Set or query x-axis tick labels

collapse all in page

Syntax

xticklabels(labels)

xl = xticklabels

xticklabels('auto')

xticklabels('manual')

m = xticklabels('mode')

___ = xticklabels(ax,___)

Description

example

xticklabels(labels) sets the x-axis tick labels for the current axes. Specify labels as a string array or a cell array of character vectors; for example, {'January','February','March'}. If you specify the labels, then the x-axis tick values and tick labels no longer update automatically based on changes to the axes.

xl = xticklabels returnsthe x-axis tick labels for the current axes.

example

xticklabels('auto') sets an automatic mode,enabling the axes to determine the x-axis ticklabels. Use this option if you set the labels and then want to setthem back to the default values.

xticklabels('manual') sets a manual mode,freezing the x-axis tick labels at the currentvalues.

m = xticklabels('mode') returnsthe current value of the x-axis tick labels mode,which is either 'auto' or 'manual'.By default, the mode is automatic unless you specify the tick labelsor set the mode to manual.

example

___ = xticklabels(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 labels (1)

Display x-Axis Tick Labels in Terms of Pi

Open Live Script

Create a line plot. Specify the x-axis limits and display tick marks along at 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 labels (2)

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

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

Set or query x-axis tick labels (3)

Specify x-Axis Tick Labels 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. Create two plots of random data. Set the x-axis tick values and labels for the second plot by specifying ax2 as the first input argument.

tiledlayout(2,1)ax1 = nexttile;plot(ax1,rand(3))ax2 = nexttile;plot(ax2,rand(3))xticks(ax2,[1 2 3])xticklabels(ax2,{'one','two','three'})

Set or query x-axis tick labels (4)

Set x-Axis Tick Labels Back to Default Labels

Open Live Script

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

stem(1:10)xticks([1 4 6 10])xticklabels({'A','B','C','D'})

Set or query x-axis tick labels (5)

xticks('auto')xticklabels('auto')

Set or query x-axis tick labels (6)

Remove x-Axis Tick Labels

Open Live Script

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

plot(rand(5))xticklabels({})

Set or query x-axis tick labels (7)

Input Arguments

collapse all

labelsTick labels
cell array of character vectors | string array | categorical array

Tick labels, specified as a cell array of character vectors, string array, or categorical array. If you do not want tick labels to show, then specify an empty cell array {}. Tick labels support TeX and LaTeX markup. See the TickLabelInterpreter property of the Axes object for more information.

Example: xticklabels({'0','\pi','2\pi'})

Example: xticklabels({'January','February','March'})

Example: xticklabels({})

Note

  • To specify the tick values, use the xticks function.

  • If you do not specify enough labels for all the ticks values, MATLAB® uses the labels followed by empty character vectors for the remaining ticks.

  • If you specify the tick labels as a categorical array, MATLAB uses the values in the array, not the categories.

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 xticklabels modifies the current axes.

Output Arguments

collapse all

xl — Current tick labels
cell array of character vectors | character array

Current tick labels, returned as a cell array of character vectors or a character array.

m — Current tick labels mode
'auto' | 'manual'

Current tick labels mode, returned as one of these values:

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

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

More About

collapse all

Tick Labels

The tick labels are the labels that you seenext to each tick mark. The tick values are the locations along the x-axiswhere the tick marks appear. Set the values using the xticks function. Set the correspondinglabels using the xticklabels function.

Set or query x-axis tick labels (8)

Algorithms

The xticklabels function sets and queriesseveral axes properties related to the x-axistick labels.

  • XTickLabel — Property that storesthe text for the x-axis tick labels.

  • XTickLabelMode — Property thatstores the x-axis tick label mode. When you setthe x-axis tick labels using xticklabels,this property changes to 'manual'.

  • XTickMode — Property that storesthe x-axis tick value mode. When you set the x-axistick labels using xticklabels, this property changesto 'manual'.

Version History

Introduced in R2016b

See Also

Functions

  • xtickformat | xticks | xlim | xsecondarylabel | xtickangle

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 labels (9)

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 labels (2024)
Top Articles
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 6004

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.