- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Hide axis values but keep axis tick labels in matplotlib
To hide the axis value but to keep the axis tick labels, we can perform the following steps −
Plot a line using the plot( ) method.
Set X and Y labels using x label and y label methods.
Using plt.gca(), get the current axis, creating one if necessary.
Use xaxis.set_ticklabels() with an empty list.
Use yaxis.set_ticklabels() with an empty list.
To show the diagram, use the plt.show() method.
Example
import matplotlib.pyplot as plt plt.plot([0, 5], [0, 5]) plt.ylabel("Y-axis ") plt.xlabel("X-axis ") ax = plt.gca() ax.axes.xaxis.set_ticklabels([]) ax.axes.yaxis.set_ticklabels([]) plt.show()
Output
- Related Articles
- How to hide axes but keep axis-labels in 3D Plot with Matplotlib?
- Show tick labels when sharing an axis in Matplotlib
- How to change the separation between tick labels and axis labels in Matplotlib?
- How to hide the Y-axis tick labels on a chart in Python Plotly?
- Overlapping Y-axis tick label and X-axis tick label in Matplotlib
- How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?
- How to rotate X-axis tick labels in Pandas bar plot?
- Increasing the space for X-axis labels in Matplotlib
- Hiding major tick labels while showing minor tick labels in Matplotlib
- Turn off the left/bottom axis tick marks in Matplotlib
- How do I convert (or scale) axis values and redefine the tick frequency in Matplotlib?
- Centering x-tick labels between tick marks in Matplotlib
- Tweaking axis labels and names orientation for 3D plots in Matplotlib
- How to turn off the upper/right axis tick marks in Matplotlib?
- Changing the color of a single X-axis tick label in Matplotlib

Advertisements