How to use pyplot.rc Change Legend Font Size In Matplotlib

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:

Python3




import matplotlib.pyplot as plt
import numpy as np
from pylab import *
 
x = np.linspace(0, (2*np.pi), endpoint = True)
 
xlim(x.min(), x.max())
 
xticks([0, np.pi/2, np.pi, (3*np.pi/2), (2*np.pi)],
       [r'$0$', r'$+\pi/2$', r'$+\pi$', r'$3/2\pi$', r'$2\pi$'])
 
ylim(-1, 0, 1)
yticks([-1, 0, +1],
       [r'$-1$', r'$0$', r'$+1$'])
 
plt.plot(x, np.sin(x), label = "sin(x)")
plt.plot(x, np.cos(x), label = "cos(x)")
 
plt.title('Trigonometric Functions', fontsize = 22)
 
plt.xlabel('Angles', fontsize = 18)
plt.ylabel('Values', fontsize = 18)
 
plt.legend(loc = 'upper center')
 
plt.rc('legend', fontsize = 16)
 
#plt.grid()
plt.tight_layout()
 
plt.show()


Output:

 



How to Change Legend Font Size in Matplotlib?

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.

Similar Reads

Using pyplot.legend Change Legend Font Size

Example 1: using fontsize...

Using pyplot.rc Change Legend Font Size

...

Contact Us