matplotlib.pyplot.xticks#

matplotlib.pyplot.xticks(ticks=None,labels=None,*,minor=False,**kwargs)[source]#

Get or set the current tick locations and labels of the x-axis.

Pass no arguments to return the current values without modifying them.

Parameters:
ticksarray-like, optional

The list of xtick locations. Passing an empty list removes all xticks.

labelsarray-like, optional

The labels to place at the giventicks locations. This argument canonly be passed ifticks is passed as well.

minorbool, default: False

IfFalse, get/set the major ticks/labels; ifTrue, the minorticks/labels.

**kwargs

Text properties can be used to control the appearance of the labels.

Warning

This only sets the properties of the current ticks, which isonly sufficient if you either passticks, resulting in afixed list of ticks, or if the plot is static.

Ticks are not guaranteed to be persistent. Various operationscan create, delete and modify the Tick instances. There is animminent risk that these settings can get lost if you work onthe figure further (including also panning/zooming on adisplayed figure).

Usetick_params instead if possible.

Returns:
locs

The list of xtick locations.

labels

The list of xlabelText objects.

Notes

Calling this function with no arguments (e.g.xticks()) is the pyplotequivalent of callingget_xticks andget_xticklabels onthe current Axes.Calling this function with arguments is the pyplot equivalent of callingset_xticks andset_xticklabels on the current Axes.

Examples

>>>locs,labels=xticks()# Get the current locations and labels.>>>xticks(np.arange(0,1,step=0.2))# Set label locations.>>>xticks(np.arange(3),['Tom','Dick','Sue'])# Set text labels.>>>xticks([0,1,2],['January','February','March'],...rotation=20)# Set text labels and properties.>>>xticks([])# Disable xticks.

Examples usingmatplotlib.pyplot.xticks#

Table Demo

Table Demo

Rotated tick labels

Rotated tick labels