Reputation: 93
I want to be able to change the font of the legend from the default to Times New Roman. I have managed to change the font of the axis labels and ticks but I am unsure of what to do. Bellow is what I have tried so far:
tnrfont = {'fontname':'Times New Roman'}
plt.figure(figsize=(12,6))
plt.scatter(N,R0_Top[:,0],s=20,marker='x',color='#0000ff',label='Top DBR')
plt.scatter(N,R0_Bottom[:,0],s=20,marker='x',color='#e60000',label='Bottom DBR (100%)')
plt.xlabel('Percentage of Aluminium',**tnrfont)
plt.ylabel('Reflectance',**tnrfont)
plt.xlim(-2,102)
plt.ylim(-0.05,1.05)
plt.minorticks_on()
plt.grid(which='both')
plt.legend(loc=0,**tnrfont)
plt.xticks(**tnrfont)
plt.yticks(**tnrfont)
plt.rcParams.update({'font.size': 28})
How can I change the font of the legend?
Upvotes: 2
Views: 6874
Reputation: 339775
To set the font of the legend labels you can use the prop
argument to plt.legend
. It will accept any FontProperty in form of a dictionary.
plt.legend(... , prop={"family":"Times New Roman"})
If you want to change the font of all of the figure's text, you may be better off by setting the font in the rcParams at the beginning of the script:
plt.rcParams["font.family"] = "Times New Roman"
Upvotes: 3