- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
- 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.
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()
Now, uncomment the line "line1.remove()" and execute the code again. It will produce the following output −
- How to hide axes and gridlines in Matplotlib?
- How to plot overlapping lines in Matplotlib?
- How to remove lines in a Matplotlib plot?
- 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 can I hide the axes in Matplotlib 3D?
- How to draw grid lines behind Matplotlib bar graph?
- How to draw axis lines inside a plot in Matplotlib?
- How to plot the lines first and points last in Matplotlib?
- How to name different lines in the same plot of Matplotlib?
- How to remove grid lines from an image in Python Matplotlib?
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
- Fill between two vertical lines in matplotlib
- Drawing lines between two plots in Matplotlib