- 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
How to hide lines in Matplotlib?
To hide lines in Matplotlib, we can use line.remove() method.
Steps
- Set the figure size and adjust the padding between and around the subplots.
- Create x, y1 and y2 data points using numpy.
- Make lines, i.e., line1 and line2, using plot() method.
- To hide the lines, use line.remove() method.
- Place a legend on the figure at the upper-right location.
- To display the figure, use show() method.
Example
import matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-10, 10, 100) y1 = np.sin(x) y2 = np.cos(x) line1, = plt.plot(x, y1, label="Line 1") line2, = plt.plot(x, y2, label="Line 2") # line1.remove() plt.legend(loc="upper right") plt.show()
Output
Now, uncomment the line "line1.remove()" and execute the code again. It will produce the following output −
- Related Articles
- How to hide axes and gridlines in Matplotlib?
- How to plot overlapping lines in Matplotlib?
- How to remove lines in a Matplotlib plot?
- How can I hide the axes in Matplotlib 3D?
- Hide Matplotlib descriptions in Jupyter notebook
- How to make markers on lines smaller in Matplotlib?
- How to draw more type of lines in Matplotlib?
- How to draw axis lines inside a plot in Matplotlib?
- How to hide axes but keep axis-labels in 3D Plot with Matplotlib?
- How to draw grid lines behind Matplotlib bar graph?
- How to remove grid lines from an image in Python Matplotlib?
- How to name different lines in the same plot of Matplotlib?
- How to plot the lines first and points last in Matplotlib?
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
- How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?

Advertisements