snippetpythonCriticalCanonical
How do I set the figure title and axes labels font size?
Viewed 0 times
titlehowfontandfiguresetthelabelssizeaxes
Problem
I am creating a figure in Matplotlib like this:
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 (
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?Solution
Functions dealing with text like
For globally setting
(As far as I can see, there is no way to set
And I see that
label, title, etc. accept parameters same as matplotlib.text.Text. For the font size you can use size/fontsize:from matplotlib import pyplot as plt
fig = plt.figure()
plt.plot(data)
fig.suptitle('test title', fontsize=20)
plt.xlabel('xlabel', fontsize=18)
plt.ylabel('ylabel', fontsize=16)
fig.savefig('test.jpg')For globally setting
title and label sizes, mpl.rcParams contains axes.titlesize and axes.labelsize. (From the page):axes.titlesize : large # fontsize of the axes title
axes.labelsize : medium # fontsize of the x any y labels(As far as I can see, there is no way to set
x and y label sizes separately.)And I see that
axes.titlesize does not affect suptitle. I guess, you need to set that manually.Code Snippets
from matplotlib import pyplot as plt
fig = plt.figure()
plt.plot(data)
fig.suptitle('test title', fontsize=20)
plt.xlabel('xlabel', fontsize=18)
plt.ylabel('ylabel', fontsize=16)
fig.savefig('test.jpg')axes.titlesize : large # fontsize of the axes title
axes.labelsize : medium # fontsize of the x any y labelsContext
Stack Overflow Q#12444716, score: 1263
Revisions (0)
No revisions yet.