snippetpythonCriticalCanonical
How to change the font size on a matplotlib plot
Viewed 0 times
howfontplotthematplotlibchangesize
Problem
How does one change the font size for all elements (ticks, labels, title) on a matplotlib plot?
I know how to change the tick label sizes, this is done with:
But how does one change the rest?
I know how to change the tick label sizes, this is done with:
import matplotlib
matplotlib.rc('xtick', labelsize=20)
matplotlib.rc('ytick', labelsize=20)But how does one change the rest?
Solution
From the matplotlib documentation,
This sets the font of all items to the font specified by the kwargs object,
Alternatively, you could also use the
or
You can find a full list of available properties on the Customizing matplotlib page.
font = {'family' : 'normal',
'weight' : 'bold',
'size' : 22}
matplotlib.rc('font', **font)This sets the font of all items to the font specified by the kwargs object,
font.Alternatively, you could also use the
rcParams update method as suggested in this answer:matplotlib.rcParams.update({'font.size': 22})or
import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 22})You can find a full list of available properties on the Customizing matplotlib page.
Code Snippets
font = {'family' : 'normal',
'weight' : 'bold',
'size' : 22}
matplotlib.rc('font', **font)matplotlib.rcParams.update({'font.size': 22})import matplotlib.pyplot as plt
plt.rcParams.update({'font.size': 22})Context
Stack Overflow Q#3899980, score: 1172
Revisions (0)
No revisions yet.