user3076813
user3076813

Reputation: 519

matplotlib legend: How to specify font weight?

What is the best way to specify the font weight for a matplotlib legend? I can use:

matplotlib.rcParams.update({'legend.fontsize':12})

to set the font size but when I use

matplotlib.rcParams.update({'legend.fontweight':'bold'}

It complains that "'legend.fontweight' is not a valid rc parameter"

Upvotes: 19

Views: 53473

Answers (1)

Ffisegydd
Ffisegydd

Reputation: 53728

You can pass parameters into plt.legend using the prop argument. This dictionary allows you to select text properties for the legend.

import matplotlib
import matplotlib.pyplot as plt

legend_properties = {'weight':'bold'}

plt.plot([1,2,3], [4,5,6], label='Test')
plt.legend(prop=legend_properties)

plt.show()

example plot

Upvotes: 16

Related Questions