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"
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With