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:
JavaScript
x
4
1
import matplotlib
2
matplotlib.rc('xtick', labelsize=20)
3
matplotlib.rc('ytick', labelsize=20)
4
But how does one change the rest?
Advertisement
Answer
From the matplotlib documentation,
JavaScript
1
6
1
font = {'family' : 'normal',
2
'weight' : 'bold',
3
'size' : 22}
4
5
matplotlib.rc('font', **font)
6
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:
JavaScript
1
2
1
matplotlib.rcParams.update({'font.size': 22})
2
or
JavaScript
1
3
1
import matplotlib.pyplot as plt
2
plt.rcParams.update({'font.size': 22})
3
You can find a full list of available properties on the Customizing matplotlib page.