- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 modify a Matplotlib legend after it has been created?
To modify a Matplotlib legend after it has been created, we can have multiple methods to modify the created legend.
- Set the figure size and adjust the padding between and around the subplots.
- Plot a line using plot() method, with two lists and a label.
- Use legend() method to place a legend over the plot.
- To modify the matplotlib legend, use set_title() method.
- To display the figure, use show() method.
Example
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.plot([1, 3, 4, 5, 2, 1], [3, 4, 1, 3, 0, 1], label="line plot", color='red', lw=0.5) leg = plt.legend(loc="upper right") leg.set_title("Title") plt.show()
Output
- Related Articles
- How to share x axes of two subplots after they have been created in Matplotlib?
- How to show a figure that has been closed in Matplotlib?
- How to create a draggable legend in Matplotlib?
- How to add a legend to a Matplotlib pie chart?
- How to position and align a Matplotlib figure legend?
- How to add legend to imshow() in Matplotlib?
- How to adjust the size of a Matplotlib legend box?
- How to show legend elements horizontally in Matplotlib?
- How to change the legend fontname in Matplotlib?
- How to create a legend for a 3D bar in Matplotlib?
- How to modify the font size in Matplotlib-venn?
- How to align rows in a Matplotlib legend with 2 columns?
- How to place customized legend symbols on a plot using Matplotlib?
- Text alignment in a Matplotlib legend
- How to remove the boxes around legend of a plot created by ggplot2 in R?

Advertisements