如何设置 matplotlib 图例中缩略图/图标的大小?一种方法是使用 plt.setp(fig.gca().get_legend().get_texts(), fontsize='15')
操纵图例中的文本大小,使图标看起来相对较大/较小。 。
有没有直接的方法来更改代表图例中的图的缩略图/图标的大小?
import numpy as np
from matplotlib import pyplot as plt
plt.rc('text', usetex = True)
font = {'family' : 'normal',
'weight' : 'normal',
'size' : 25}
plt.rc('font', **font)
fig, ax = plt.subplots(1, 1)
a = np.arange(10)
b = np.random.randn(10)
ax.errorbar(a, b, yerr=0.5, fmt='o', color='g', ecolor='g', capthick=1, linestyle = '-', linewidth=2, elinewidth=1, label = "Test")
legend = plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=2, ncol=6, mode="expand", borderaxespad=0.2)
fig.set_size_inches(14.5, 10.5)
plt.savefig('/Users/Cupitor/Test.png')
最佳答案
为此有一个markerscale
参数。 >1 值表示绘图标记大于实际绘图上的标记,即:
legend = plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=2,
ncol=6, mode="expand", borderaxespad=0.2,
markerscale=1.5)
关于python - 如何设置matplotlib图例中缩略图的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32167674/