I seem to have a problem in figuring out how to increase or decrease the fontsize of both the x and y tick labels while using matplotlib.
I am aware that there is the set_xticklabels(labels, fontdict=None, minor=False, **kwargs) function, but I failed to understand how to control the fontsize in it.
I expected something somehow explicit, like
title_string=('My Title')
plt.suptitle(title_string, y=1.0, fontsize=17)
but I haven't found anything like that so far. What am I missing?
解决方案
You can set the fontsize directly in the call to set_xticklabels and set_yticklabels (as noted in previous answers). This will only affect one Axes at a time.
ax.set_xticklabels(x_ticks, rotation=0, fontsize=8)
ax.set_yticklabels(y_ticks, rotation=0, fontsize=8)
You can also set the ticklabel font size globally (i.e. for all figures/subplots in a script) using rcParams:
import matplotlib.pyplot as plt
plt.rc('xtick',labelsize=8)
plt.rc('ytick',labelsize=8)
Or, equivalently:
plt.rcParams['xtick.labelsize']=8
plt.rcParams['ytick.labelsize']=8
Finally, if this is a setting that you would like to be set for all your matplotlib plots, you could also set these two rcParams in your matplotlibrc file:
xtick.labelsize : 8 # fontsize of the x tick labels
ytick.labelsize : 8 # fontsize of the y tick labels