matplotlib.axes.Axes.set_xticks#

Axes.set_xticks(ticks, labels=None, *, minor=False, **kwargs)[source]#

Set the xaxis' tick locations and optionally tick labels.

If necessary, the view limits of the Axis are expanded so that all given ticks are visible.

Parameters:
ticks1D array-like

Array of tick locations (either floats or in axis units). The axis Locator is replaced by a FixedLocator.

Pass an empty list (set_xticks([])) to remove all ticks.

Some tick formatters will not label arbitrary tick positions; e.g. log formatters only label decade ticks by default. In such a case you can set a formatter explicitly on the axis using Axis.set_major_formatter or provide formatted labels yourself.

labelslist of str, optional

Tick labels for each location in ticks; must have the same length as ticks. If set, the labels are used as is, via a FixedFormatter. If not set, the labels are generated using the axis tick Formatter.

minorbool, default: False

If False, set only the major ticks; if True, only the minor ticks.

**kwargs

Text properties for the labels. Using these is only allowed if you pass labels. In other cases, please use tick_params.

Notes

The mandatory expansion of the view limits is an intentional design choice to prevent the surprise of a non-visible tick. If you need other limits, you should set the limits explicitly after setting the ticks.

Examples using matplotlib.axes.Axes.set_xticks#

Grouped bar chart with labels

Grouped bar chart with labels

Hat graph

Hat graph

Multicolored lines

Multicolored lines

Power spectral density (PSD)

Power spectral density (PSD)

Annotated heatmap

Annotated heatmap

Box plot vs. violin plot comparison

Box plot vs. violin plot comparison

Violin plot customization

Violin plot customization

Multiple histograms side by side

Multiple histograms side by side

Multiline

Multiline

Render math equations using TeX

Render math equations using TeX

ggplot style sheet

ggplot style sheet

Align histogram to scatter plot using locatable Axes

Align histogram to scatter plot using locatable Axes

Simple Axisline4

Simple Axisline4

Ticklabel alignment

Ticklabel alignment

Ticklabel direction

Ticklabel direction

Integral as the area under a curve

Integral as the area under a curve

Shaded & power normalized rendering

Shaded & power normalized rendering

XKCD

XKCD

Rain simulation

Rain simulation

Matplotlib unchained

Matplotlib unchained

Log Bar

Log Bar

Rotated tick labels

Rotated tick labels

Group barchart with units

Group barchart with units

The Lifecycle of a Plot

The Lifecycle of a Plot

Axis ticks

Axis ticks