这里有一个简单的问题:我试图使用matplotlib获取传说的大小。Pyplot更小(即,文本更小)。我使用的代码是这样的:

plot.figure()
plot.scatter(k, sum_cf, color='black', label='Sum of Cause Fractions')
plot.scatter(k, data[:, 0],  color='b', label='Dis 1: cf = .6, var = .2')
plot.scatter(k, data[:, 1],  color='r',  label='Dis 2: cf = .2, var = .1')
plot.scatter(k, data[:, 2],  color='g', label='Dis 3: cf = .1, var = .01')
plot.legend(loc=2)

当前回答

除了以点为单位的大小,还有一些命名的fontsizes:

xx-small
x-small
small
medium
large
x-large
xx-large

用法:

pyplot.legend(loc=2, fontsize = 'x-small')

其他回答

除了以点为单位的大小,还有一些命名的fontsizes:

xx-small
x-small
small
medium
large
x-large
xx-large

用法:

pyplot.legend(loc=2, fontsize = 'x-small')

您可以减少图例大小设置:

plt.legend(labelspacing=y, handletextpad=x,fontsize)  

Labelspacing是每个标签之间的垂直空间。 Handletextpad是实际的传说和你的距离 标签。 fontsize不言自明

现在在2021年,使用matplotlib 3.4.2,您可以设置您的图例字体

plt.legend(title="My Title", fontsize=10, title_fontsize=15)

其中fontsize是图例中项目的字体大小,title_fontsize是图例标题的字体大小。更多信息请参阅matplotlib文档

plot.legend(loc = 'lower right', decimal_places = 2, fontsize = '11', title = 'Hey there', title_fontsize = '20')

这应该可以

import pylab as plot
params = {'legend.fontsize': 20,
          'legend.handlelength': 2}
plot.rcParams.update(params)

然后再做绘图。

还有很多其他的rcParams,它们也可以在matplotlibrc文件中设置。

你也可以通过matplotlib.font_manager来改变它。FontProperties实例,但我不知道如何做。——>见Yann的回答。