如何在 matplotlib 中调整图例标记和标签之间的间距?


要调整图例标记和标签之间的间距,我们可以在图例方法中使用 labelspacing。

步骤

  • 使用 label1label2 label3 绘制线条。

  • 初始化一个空间变量以增加或减少图例标记和标签之间的间距。

  • 在参数中使用 legend 方法与 labelspacing 

  • 要显示图形,请使用 show() 方法。

示例

from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.plot([0, 1], [0, 1.0], label='Label 1')
plt.plot([0, 1], [0, 1.1], label='Label 2')
plt.plot([0, 1], [0, 1.2], label='Label 3')
space = 2
plt.legend(labelspacing=space)
plt.show()

输出

更新于: 11-May-2021

3K+ 浏览量

开启你的 事业

通过完成课程获得认证

开始吧
广告
© . All rights reserved.