I am creating a figure in Matplotlib like this:
from matplotlib import pyplot as plt
fig = plt.figure()
plt.plot(data)
fig.suptitle('test title')
plt.xlabel('xlabel')
plt.ylabel('ylabel')
fig.savefig('test.jpg')
I want to specify font sizes for the figure title and the axis labels. I need all three to be different font sizes, so setting a global font size (mpl.rcParams['font.size']=x
) is not what I want. How do I set font sizes for the figure title and the axis labels individually?
Best Answer
Functions dealing with text like
label
,title
, etc. accept parameters same asmatplotlib.text.Text
. For the font size you can usesize/fontsize
:For globally setting
title
andlabel
sizes,mpl.rcParams
containsaxes.titlesize
andaxes.labelsize
. (From the page):(As far as I can see, there is no way to set
x
andy
label sizes separately.)And I see that
axes.titlesize
does not affectsuptitle
. I guess, you need to set that manually.