

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to hide axes and gridlines in Matplotlib?
To hide axes (X and Y) and gridlines, we can take the following steps −
Create x and y points using numpy.
Plot a horizontal line (y=0) for X-Axis, using the plot() method with linestyle, labels.
Plot x and y points using the plot() method with linestyle, labels.
To hide the grid, use plt.grid(False).
To hide the axes, use plt.axis('off')
To activate the labels' legend, use the legend() method.
To display the figure, use the show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 50) y = np.sin(x) plt.axhline(y=0, c="green", linestyle="dashdot", label="y=0") plt.plot(x, y, c="red", lw=5, linestyle="dashdot", label="y=sin(x)") plt.grid(False) plt.axis('off') plt.legend() plt.show()
Output
- Related Questions & Answers
- How can I hide the axes in Matplotlib 3D?
- How to hide axes but keep axis-labels in 3D Plot with Matplotlib?
- Adjusting gridlines and ticks in Matplotlib imshow
- How to hide lines in Matplotlib?
- How to switch axes in Matplotlib?
- How to make axes transparent in Matplotlib?
- How to create a bar graph using ggplot2 without horizontal gridlines and Y-axes labels in R?
- How to rotate a simple matplotlib Axes?
- How to change axes background color in Matplotlib?
- Add minor gridlines to Matplotlib plot using Seaborn
- Getting vertical gridlines to appear in line plot in matplotlib
- How to align the bar and line in Matplotlib two Y-axes chart?
- Hide Matplotlib descriptions in Jupyter notebook
- Change x axes scale in matplotlib
- How to get a matplotlib Axes instance to plot to?
Advertisements