How to Remove Ticks and Tick Labels in Matplotlib

To remove tick labels in Matplotlib but keep the tick marks, use ax.tick_params(labelbottom=False, labelleft=False). To remove the ticks and their labels together, use ax.set_xticks([]) and ax.set_yticks([]) (or plt.xticks([]) with pyplot), and to hide everything including the frame, use ax.axis("off"). This guide compares all of these on real plots, then shows how to remove tick labels from subplots, from a single axis, and how to remove only minor ticks.

Tested with Python 3.12.5 and Matplotlib 3.11.2; the plots are real Matplotlib windows. Full parameter list: Axes.tick_params and Axes.set_xticks.

Quick comparison

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
fig, axes = plt.subplots(2, 2, figsize=(8, 5.5))
for ax in axes.flat:
    ax.plot(x, np.sin(x))

axes[0, 0].set_title("Default")

axes[0, 1].set_xticks([])                     # no x ticks and no x tick labels
axes[0, 1].set_yticks([])
axes[0, 1].set_title("set_xticks([]) + set_yticks([])")

axes[1, 0].tick_params(labelbottom=False, labelleft=False)   # keep the tick marks
axes[1, 0].set_title("Labels removed, ticks kept")

axes[1, 1].tick_params(length=0)              # keep the labels, hide the tick marks
axes[1, 1].set_title("Tick marks removed, labels kept")
plt.tight_layout()
plt.show()
Four Matplotlib subplots comparing default ticks, ticks removed with set_xticks([]), tick labels removed with tick_params and tick marks removed with length=0
What each method removes.
GoalCode
Remove x tick marks and labelsax.set_xticks([]) or plt.xticks([])
Remove y tick marks and labelsax.set_yticks([]) or plt.yticks([])
Remove tick labels, keep tick marksax.tick_params(labelbottom=False, labelleft=False)
Remove tick marks, keep labelsax.tick_params(length=0)
Remove ticks, labels and frameax.axis("off")
Remove a whole axis (ticks + label)ax.yaxis.set_visible(False)
Remove only minor ticksax.minorticks_off()

Remove ticks with plt.xticks([]) and plt.yticks([])

With the pyplot interface, pass an empty list to plt.xticks() or plt.yticks():

import matplotlib.pyplot as plt

plt.bar(["North", "South", "East", "West"], [42, 35, 51, 28], color="tab:purple")
plt.yticks([])                 # pyplot: remove the y ticks and labels
plt.title("Orders by region (y-axis ticks removed)")
plt.show()
Matplotlib bar chart of orders by region with the y-axis ticks and tick labels removed using plt.yticks([])
plt.yticks([]) removes the y ticks and their labels.

Remove tick labels but keep the ticks

tick_params() switches labels on each side on or off: labelbottom, labeltop, labelleft, labelright. The ticks stay, so gridlines and zooming still work. Emptying the labels with set_xticklabels([]) also works, but giving new labels that way without setting the tick positions first triggers a warning:

import warnings
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

warnings.simplefilter("always")

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

ax.tick_params(labelbottom=False)
first = ax.xaxis.get_major_ticks()[0]
print("tick_params -> label visible:", first.label1.get_visible(), "| tick mark visible:", first.tick1line.get_visible())

ax.tick_params(labelbottom=True)
ax.set_xticklabels([])                       # empty labels: works without a warning
print("set_xticklabels([]) -> label texts:", [t.get_text() for t in ax.get_xticklabels()][:3])

ax.set_xticklabels(["a", "b", "c"])          # new labels without set_xticks(): warning

Output:

tick_params -> label visible: False | tick mark visible: True
set_xticklabels([]) -> label texts: ['', '', '']
C:\pyguides\remove_tick_labels_check.py:20: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator. Otherwise, ticks may be mislabeled.
  ax.set_xticklabels(["a", "b", "c"])          # new labels without set_xticks(): warning
Command Prompt output showing tick_params hiding labels, set_xticklabels([]) emptying labels and the set_ticklabels FixedLocator UserWarning
Both ways of hiding labels, and the warning you get when you set new labels without set_xticks().

In Matplotlib 3.x, use labelbottom=False (a boolean). The old labelbottom="off" string form from Matplotlib 1.x no longer works.

Remove ticks, labels and the frame with axis(‘off’)

For images and diagrams you usually want nothing around the data. ax.axis("off") (or ax.set_axis_off()) hides the ticks, tick labels, axis labels and the spines:

import matplotlib.pyplot as plt
import numpy as np

img = np.random.default_rng(1).random((12, 12))
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4))

ax1.imshow(img, cmap="viridis")
ax1.set_title("Default: ticks on the image")

ax2.imshow(img, cmap="viridis")
ax2.axis("off")                               # remove ticks, labels AND the frame
ax2.set_title("ax.axis('off')")
plt.tight_layout()
plt.show()
Two Matplotlib imshow images, the left with ticks around it and the right with ticks, labels and frame removed by ax.axis('off')
ax.axis("off") on the right.

If you want to keep the frame but drop the ticks, use set_xticks([]) and set_yticks([]) instead.

Remove tick labels from subplots

Only keep labels on the outer subplots

In a grid of subplots, repeated tick labels waste space. ax.label_outer() keeps x labels only on the bottom row and y labels only on the left column. plt.subplots(..., sharex=True, sharey=True) does the same automatically.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
fig, axes = plt.subplots(2, 3, figsize=(9, 5))
for i, ax in enumerate(axes.flat, start=1):
    ax.plot(x, np.sin(x * i / 3))
    ax.set_title(f"Plot {i}")
    ax.label_outer()                          # keep tick labels only on the outer edges
plt.tight_layout()
plt.show()
Grid of six Matplotlib subplots where label_outer keeps tick labels only on the bottom row and left column
label_outer() removes the inner tick labels.

Remove the y-axis from one subplot

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(9, 3.4))
ax1.plot(x, np.sin(x))
ax2.plot(x, np.cos(x))
ax3.plot(x, np.sin(x) * np.cos(x))

ax2.tick_params(labelleft=False)              # hide y labels on the middle subplot only
ax3.yaxis.set_visible(False)                  # remove the whole y-axis on the right subplot
ax1.set_title("unchanged")
ax2.set_title("labelleft=False")
ax3.set_title("yaxis.set_visible(False)")
plt.tight_layout()
plt.show()
Three Matplotlib subplots: unchanged, y tick labels hidden with labelleft=False, and the whole y-axis removed with yaxis.set_visible(False)
Hide just the labels, or the whole y-axis, on individual subplots.

Remove minor ticks

Log-scale axes add many small minor ticks. ax.minorticks_off() removes them and keeps the major ticks:

import matplotlib.pyplot as plt
import numpy as np

x = np.logspace(0, 3, 50)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 3.6))
for ax in (ax1, ax2):
    ax.loglog(x, x ** 1.5)
ax1.set_title("Log axes: major + minor ticks")
ax2.minorticks_off()                          # remove only the small minor ticks
ax2.set_title("minorticks_off()")
plt.tight_layout()
plt.show()
Two Matplotlib log-log plots, the left with major and minor ticks and the right with minor ticks removed by minorticks_off
Minor ticks removed on the right.

Remove axis labels

Axis labels are separate from tick labels. Remove them with an empty string, or hide them:

ax.set_xlabel("")                       # remove the x-axis label
ax.yaxis.label.set_visible(False)       # hide the y-axis label

To style or move them instead, see the Matplotlib x-axis label guide.

Related Matplotlib tick tutorials:

Frequently asked questions

How do I remove tick labels in Matplotlib?

Use ax.tick_params(labelbottom=False, labelleft=False) to hide the x and y tick labels and keep the tick marks.

How do I remove ticks in Matplotlib?

Use ax.set_xticks([]) and ax.set_yticks([]), or plt.xticks([]) and plt.yticks([]). The tick marks and their labels both disappear.

How do I remove tick labels but keep the ticks?

ax.tick_params(labelbottom=False) for the x-axis and labelleft=False for the y-axis. ax.set_xticklabels([]) also works.

How do I remove the x-axis and y-axis completely?

ax.axis("off") removes ticks, labels and the frame. To remove only one axis, use ax.xaxis.set_visible(False) or ax.yaxis.set_visible(False).

How do I remove tick labels from subplots?

Use sharex=True / sharey=True in plt.subplots() or call ax.label_outer() on each subplot; for one subplot, use tick_params() on that axes.

How do I remove tick marks but keep the labels?

Set the tick length to zero: ax.tick_params(length=0).