python怎么改变字体大小_如何在matplotlib图上更改字体大小

如果你像我这样的控制狂,你可能想要明确设置你所有的字体大小:

import matplotlib.pyplot as plt

SMALL_SIZE = 8

MEDIUM_SIZE = 10

BIGGER_SIZE = 12

plt.rc('font', size=SMALL_SIZE) # controls default text sizes

plt.rc('axes', titlesize=SMALL_SIZE) # fontsize of the axes title

plt.rc('axes', labelsize=MEDIUM_SIZE) # fontsize of the x and y labels

plt.rc('xtick', labelsize=SMALL_SIZE) # fontsize of the tick labels

plt.rc('ytick', labelsize=SMALL_SIZE) # fontsize of the tick labels

plt.rc('legend', fontsize=SMALL_SIZE) # legend fontsize

plt.rc('figure', titlesize=BIGGER_SIZE) # fontsize of the figure title

请注意,您还可以设置调用rc方法的大小matplotlib:

import matplotlib

SMALL_SIZE = 8

matplotlib.rc('font', size=SMALL_SIZE)

matplotlib.rc('axes', titlesize=SMALL_SIZE)

# and so on ...