using import matplotlib.pyplot as plt
Method 1: specify the fontsize when calling legend (repetitive)
plt.legend(fontsize=20) # using a size in points
plt.legend(fontsize="x-large") # using a named size
With this method you can set the fontsize for each legend at creation (allowing you to have multiple legends with different fontsizes). However, you will have to type everything manually each time you create a legend.
(Note: @Mathias711 listed the available named fontsizes in his answer)
Method 2: specify the fontsize in rcParams (convenient)
plt.rc('legend',fontsize=20) # using a size in points
plt.rc('legend',fontsize='medium') # using a named size
With this method you set the default legend fontsize, and all legends will automatically use that unless you specify otherwise using method 1. This means you can set your legend fontsize at the beginning of your code, and not worry about setting it for each individual legend.
If you use a named size e.g. 'medium'
, then the legend text will scale with the global font.size
in rcParams
. To change font.size
use plt.rc(font.size='medium')