- 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 set the font size of Matplotlib axis Legend?
To set the font size of matplotlib axis legend, we can take the following steps −
Create the points for x and y using numpy.
Plot x and y using the plot() method with label y=sin(x).
Title the plot using the title() method.
To set the fontsize, we can override rcParams legend fontsize by value 20.
Use the legend() method, and fit the legend at the top-right position.
To display the figure, use the show() method.
Example
import numpy as np from matplotlib import pyplot as plt import matplotlib plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(1, 10, 50) y = np.sin(x) plt.plot(x, y, c="red", lw=7, label="y=sin(x)") plt.title("Sine Curve") matplotlib.rcParams['legend.fontsize'] = 20 plt.legend(loc=1) plt.show()
Output
- Related Articles
- How to increase the font size of the legend in my Seaborn plot using Matplotlib?
- How to set legend marker size and alpha in Matplotlib?
- How to change the font size of legend in base R plot?
- How to adjust the size of a Matplotlib legend box?
- How to change the text color of font in the legend using Matplotlib?
- How to modify the font size in Matplotlib-venn?
- How to change the font size of scientific notation in Matplotlib?
- How to increase plt.title font size in Matplotlib?
- How to set the font size of text with JavaScript?
- How to set the font size of Entry widget in Tkinter?
- Set the font size with CSS
- How to set the font size of a Tkinter Canvas text item?
- How to change xticks font size in a matplotlib plot?
- How to set the value of the axis multiplier in matplotlib?
- How to increase the X-axis labels font size using ggplot2 in R?

Advertisements