【问题标题】:Horizontal layout of patches in legend (matplotlib)图例中补丁的水平布局(matplotlib)
【发布时间】:2016-09-09 11:10:25
【问题描述】:

我以这种方式在图表中创建图例:

legend_handles.append(matplotlib.patches.Patch(color=color1, label='group1'))
legend_handles.append(matplotlib.patches.Patch(color=color2, label='group2'))
ax.legend(loc='upper center', handles=legend_handles, fontsize='small')

这会导致图例项垂直堆叠(从上到下),而我想将它们从左到右水平放置。

我该怎么做?

(matplotlibv1.4.3)

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    有一个参数确定列数ncol=

    ax.legend(loc='upper center', handles=legend_handles, fontsize='small', ncol=2)
    

    这应该可以解决问题。从this 线程得到它。

    【讨论】:

      猜你喜欢
      • 2020-12-11
      • 2021-09-28
      • 2014-03-08
      • 1970-01-01
      • 2019-02-20
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多