- 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 name different lines in the same plot of Matplotlib?
To name different lines in the same plot of matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Make two lists of data points.
Plot point1 and point2 using plot() method.
Place a legend on the figure.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True points1 = [2, 4, 1, 5, 1] points2 = [3, 2, 0, 4, 3] plt.plot(points1, 'g--', label="plot A") plt.plot(points2, 'r-o', label="plot A") plt.legend() plt.show()
Output
- Related Articles
- How to plot overlapping lines in Matplotlib?
- How to set same color for markers and lines in a Matplotlib plot loop?
- How to remove lines in a Matplotlib plot?
- How to plot the lines first and points last in Matplotlib?
- How to plot with different scales in Matplotlib?
- How can I plot two different spaced time series on one same plot in Python Matplotlib?
- How to draw axis lines inside a plot in Matplotlib?
- How to add vertical lines to a distribution plot (sns.distplot) in Matplotlib?
- How to get different font sizes in the same annotation of Matplotlib?
- How to plot multiple histograms on same plot with Seaborn using Matplotlib?
- How to plot multiple lines on the same Y-axis in Python Plotly?
- How to plot two dotted lines and set marker using Matplotlib?
- How to use different markers for different points in a Pylab scatter plot(Matplotlib)?
- Matplotlib Plot Lines with Colors through Colormap
- How to plot a pcolor colorbar in a different subplot in Matplotlib?

Advertisements