Sunday 10 September 2023

How to adjust the font size of legend in a plot?

Using 'fontsize' parameter of 'legend' method, you can set the font size of the text in the legend.

 

Example

plt.legend(fontsize=18)

 

legend_font_size.py

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 10)
y1 = x**2
y2 = x**3

plt.plot(x, y1, label="y = x^2", color='r')
plt.plot(x, y2, label="y = x^3", color='g')

plt.legend(fontsize=18)
plt.show()

 

Output


 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment