- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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 label a line in Matplotlib (Python)?
To label a line in matplotlib, we can use label in the argument of plot() method,
- Set the figure size and adjust the padding between and around the subplots.
- Plot with label="line1" using plot() method.
- Plot with label="line2" using plot() method.
- To place a legend on the figure, use legend() method.
- To display the figure, use show() method.
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True line1, = plt.plot([1, 2, 3], label="line1") line2, = plt.plot([3, 2, 1], label="line2") leg = plt.legend(loc='upper center') plt.show()
- Related Articles
- How to set label for an already plotted line in Matplotlib?
- How to label a patch in matplotlib?
- How to use multiple font sizes in one label in Python Matplotlib?
- Putting a newline in Matplotlib label with TeX in Python
- How to put a title for a curved line in Python Matplotlib?
- How to access axis label object in Matplotlib?
- How to display all label values in Matplotlib?
- Python Plotly – How to change variable/label names for the legend in a line chart?
- How to animate a line plot in Matplotlib?
- How to customize the axis label in a Seaborn jointplot using Matplotlib?
- How to plot an emoji as a label for a bar in Matplotlib?
- How to change the font properties of a Matplotlib colorbar label?
- How to add a shared x-label and y-label to a plot created with Pandas' plot? (Matplotlib)
- How to plot a 3D continuous line in Matplotlib?
- How to plot a gradient color line in matplotlib?