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()
| Goal | Code |
|---|---|
| Remove x tick marks and labels | ax.set_xticks([]) or plt.xticks([]) |
| Remove y tick marks and labels | ax.set_yticks([]) or plt.yticks([]) |
| Remove tick labels, keep tick marks | ax.tick_params(labelbottom=False, labelleft=False) |
| Remove tick marks, keep labels | ax.tick_params(length=0) |
| Remove ticks, labels and frame | ax.axis("off") |
| Remove a whole axis (ticks + label) | ax.yaxis.set_visible(False) |
| Remove only minor ticks | ax.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()
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
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()
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()
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()
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()
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:
- Customize ticks with tick_params()
- Rotate tick labels in Matplotlib
- Set the x-axis label in Matplotlib
- Fix overlapping labels with tight_layout()
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).
Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay · Microsoft MVP profile · LinkedIn