python - 如何设置matplotlib图例中缩略图的大小

标签 python matplotlib

如何设置 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')

enter image description here

最佳答案

为此有一个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)

enter image description here

关于python - 如何设置matplotlib图例中缩略图的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32167674/

相关文章:

python - 如何绘制条件为 (r < 1.5*rs) 的数组?

用于 logit 刻度轴标签的 Python matplotlib ValueError

python - 如何在 mplot3d (matplotlib + python) 中获取所选对象的属性?

python - 我可以确保始终调用 python 基类方法吗

python - 长期在本地存储数据

Python Pydantic 错误 : TypeError: __init__() takes exactly 1 positional argument (2 given)

python - Matplotlib 条形图不绘制边界/边缘

python - 如何将图中的 DOY(一年中的某一天)转换为月份(作为文本)?

c# - 如何等待操作完成?

python - 在 python 中打开 berkeley db 时出现问题