VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-change-legend-font-size-in-matplotlib/

⇱ How to Change Legend Font Size in Matplotlib? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Change Legend Font Size in Matplotlib?

Last Updated : 23 Jul, 2025

Matplotlib is a library for creating interactive Data visualizations in Python. The functions in Matplotlib make it work like MATLAB software. The legend method in Matplotlib describes the elements in the plot. In this article, we are going to Change Legend Font Size in Matplotlib.

Using pyplot.legend Change Legend Font Size

Example 1: using fontsize

Here, we are trying to change the font size of the x and y labels.

Output:

👁 Image
 

Example 2: Changing text font size

This example changes the font size of items in the legend. The font size parameter can have integer or float values. It also accepts the string sizes like: ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large'.

Output: 

👁 Image
 

Example 3: Using prop keyword

The prop keyword is used to change the font size property. It is used in Matplotlib as Using a prop keyword for changing the font size in legend.

Output:

👁 Image
 

Using pyplot.rc Change Legend Font Size

The matplotlib.rcparams is a dictionary-like variable that has all the configuration settings to customize default parameters. The matplotlib.rc() command is used to change multiple settings with the use of keyword arguments.

Example:

Output:

👁 Image
 
Comment