Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python matplotlib make everything bold

Well , I am making some plots and wants to make everything in bold font. I can can use weight="bold" to make bold font of label to ticks. Can also use the prop={'weight':'bold'} to make the legends lines bold, but I can't make the legend title bold. So, 1st question is there a way to make the legend title bold?

2nd,I tried to used matplotlib latex support to make the title bold, that did it but if I use rc('text', usetex=True) I cant use weight=bold and have to use \textbf{} everytime, also how do I make the ticks bold in this way.

3rd , If I use latex support then the font changes that I don't like. How do use the normal matplotlib font with using latex?

like image 493
Eular Avatar asked Mar 29 '17 19:03

Eular


2 Answers

Making everything bold is rather easy. Just add

plt.rcParams["font.weight"] = "bold"
plt.rcParams["axes.labelweight"] = "bold"

at the top of the script.

enter image description here

import matplotlib.pyplot as plt
plt.rcParams["font.weight"] = "bold"
plt.rcParams["axes.labelweight"] = "bold"

plt.plot([2,3,1], label="foo")
plt.plot([3,1,3], label="bar")

plt.legend(title="Legend Title")
plt.xlabel("xLabel")

plt.show()
like image 95
ImportanceOfBeingErnest Avatar answered Oct 21 '22 04:10

ImportanceOfBeingErnest


You should be able to pass parameters into the plt.legend using the prop argument

legend_prop = {'weight':'bold'}
plt.plot(x, y, label='some label')
plt.legend(prop=legend_prop)

This would give you bold labels. Is this not what you're looking for?

like image 37
Kelvin Avatar answered Oct 21 '22 03:10

Kelvin