Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"

like image 327
user3076813 Avatar asked Feb 21 '16 15:02

user3076813


People also ask

How do I change the font size on my legend in Matplotlib?

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.


1 Answers

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

like image 99
Ffisegydd Avatar answered Sep 23 '22 08:09

Ffisegydd