- 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
Remove the X-axis ticks while keeping the grids (Matplotlib)
To remove the X-ticks while keeping the grids, we can take the following steps−
- Use gca() method to get the current axes, creating one if necessary.
- Plot the x and np.sin(x) using plot() method with linewidth=5, label y=sin(x).
- Remove yticks and xticks by passing empty array in the argument of set_xticklabels and set_yticklabels methods respectively.
- Configure grid lines by putting flag as True.
- Place the legend for the plot label in the argument.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0, 2*np.pi, 100) ax = plt.gca() ax.plot(x, np.sin(x), c='r', lw=5, label='y=sin(x)') ax.set_xticklabels([]) ax.set_yticklabels([]) ax.grid(True) plt.legend(loc="upper right") plt.show()
Output
- Related Articles
- How to customize X-axis ticks in Matplotlib?
- How to remove the digits after the decimal point in axis ticks in Matplotlib?
- Adding extra axis ticks using Matplotlib
- How to remove the first and last ticks label of each Y-axis subplot in Matplotlib?
- How to turn on minor ticks only on the y-axis Matplotlib?
- Plotting grids across the subplots in Python Matplotlib
- How to change the color of the axis, ticks and labels for a plot in matplotlib?
- How to set axis ticks in multiples of pi in Python Matplotlib?
- Updating the X-axis values using Matplotlib animation
- How to customize the X-axis in Matplotlib?
- How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?
- How do you draw R-style axis ticks that point outward from the axes in Matplotlib?
- How to change the range of the X-axis and Y-axis in Matplotlib?
- Increasing the space for X-axis labels in Matplotlib
- Show the origin axis (x,y) in Matplotlib plot

Advertisements