Last modified: 18 December 2023

How can I change the size of axis labels in a plot?


The size of axis labels in an existing plot can be changed with matplotlib commands. The plt.gca command returns an axis object which can then be used to change the tick label size (once per tick)

sherpa> plot_data()
sherpa> ax = plt.gca()
sherpa> for l in ax.get_xticklabels() + ax.get_yticklabels():
   ...:     l.set_fontsize(12)
   ...:

and to adjust the axis labels:

sherpa> ax.set_ylabel('counts s$^{-1}$ keV$^{-1}$')
sherpa> ax.xaxis.label.set_fontsize(14)
sherpa> ax.yaxis.label.set_fontsize(14)

Note that these commands may be used to change other attributes of plot labels, such as color, line thickness, and font.