
- 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 remove lines in a Matplotlib plot?
We will create two lines, i.e., line1 and line2. After that, we will pop the second line and will remove it.
Steps
Create lists for line1 and line2.
Plot line1 and line 2 using plot() method, line 2 with style =’dashed’.
Set or retrieve auto-scaling margins(0.2).
Pop line 2, and remove it using remove() method.
The final figure will have only one line, so use plt.show() method.
Example
import matplotlib.pyplot as plt line1 = [2, 4, 8] line2 = [3, 6, 12] plt.plot(line1) line_2 = plt.plot(line2, linestyle='dashed') plt.margins(0.2) plt.title("With extra lines") plt.show() plt.plot(line1) l = line_2.pop(0) l.remove() plt.margins(0.2) plt.title("Removed extra lines") plt.show()
Input Diagram (Before removal of lines)
Output Diagram
- Related Questions & Answers
- How to plot overlapping lines in Matplotlib?
- How to draw axis lines inside a plot in Matplotlib?
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
- Matplotlib Plot Lines with Colors through Colormap
- 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 plot two dotted lines and set marker using Matplotlib?
- How to set same color for markers and lines in a Matplotlib plot loop?
- How to remove scientific notation from a Matplotlib log-log plot?
- How to hide lines in Matplotlib?
- Best way to plot an angle between two lines in Matplotlib
- How to change the color and add grid lines to a Python Matplotlib surface plot?
- How to a plot stem plot in Matplotlib Python?
- How to plot a circle in Matplotlib?
Advertisements