Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Choose the Matplotlib setting that matches what you want to remove: use tick_params to hide labels while keeping tick marks, a NullLocator to remove tick positions and their labels, or set_axis_off() to hide all axis decorations.

Hide tick labels but keep the tick marks

Use tick_params when you want the marks to remain but do not want their numeric or categorical labels. For example, to hide the labels along the bottom of an x-axis:

ax.tick_params(axis="x", labelbottom=False)

For the left side of a y-axis, use labelleft=False:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ax.tick_params(axis="y", labelleft=False)

These flags control labels on specific sides. If your plot also shows labels at the top or right, set the corresponding side’s label visibility as well. To suppress labels without relying on side-specific tick-parameter flags, use a NullFormatter; it leaves tick positions under the locator’s control while formatting no labels.

Remove tick marks and labels from an axis

A locator chooses tick positions. A NullLocator places no ticks, so the labels associated with those ticks disappear too. Major and minor ticks are configured separately; set both locators if minor ticks are enabled and should also be removed.

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [2, 1, 4])

ax.xaxis.set_major_locator(ticker.NullLocator())
ax.xaxis.set_minor_locator(ticker.NullLocator())

To remove ticks from the y-axis as well, apply the same calls to ax.yaxis. If you only need to turn off minor ticks, ax.minorticks_off() removes them without affecting major ticks.

Use an empty tick list for a fixed axis

For a fixed empty set of tick positions, pass an empty list to the relevant setter:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ax.set_xticks([])
ax.set_yticks([])

Each call replaces that axis’s locator with a FixedLocator. This is a concise option when an empty, fixed tick set is what you want. If the view limits may change and the rule should remain “show no ticks,” a NullLocator states that intent directly.

Hide all axis decorations

Use ax.set_axis_off() only when you want the entire axes presentation hidden, not just its ticks. It suppresses axis labels, spines, tick marks, tick labels, and grid lines; individual visibility settings are ignored while the axis is off.

ax.set_axis_off()
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the right method

What you want Use What changes
Hide labels while retaining tick marks ax.tick_params(axis="x", labelbottom=False) or the matching side option Label visibility changes; tick positions and marks remain.
Remove all major and minor ticks on one axis NullLocator on that axis’s major and minor locators No tick positions are placed, so their labels are absent too.
Set a fixed axis to have no ticks ax.set_xticks([]) or ax.set_yticks([]) Installs a FixedLocator with no positions.
Hide every axes decoration ax.set_axis_off() Hides labels, spines, ticks, tick labels, and grid lines.

The Matplotlib 3.11.2 tick guide and ticker reference document the locator, formatter, and tick-parameter behavior. The set_yticks API reference is labeled Matplotlib 3.11.0. These documentation versions do not establish compatibility for older releases; check the documentation for the Matplotlib version installed in your environment.

References: Matplotlib tick guide, Matplotlib ticker API, Axes.set_xticks API, Axes.set_yticks API, and Axes.set_axis_off API.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.