【问题标题】:Change the order of the legend in a plot in Pandas在 Pandas 中更改图例的顺序
【发布时间】:2021-09-28 18:26:19
【问题描述】:

我一直在尝试更改 Pandas 中图例的顺序,以使其与图显示的顺序相同:

Screenshot of the code and the plot in Anaconda

如您所见,通过增加 %K 的数量,图正在堆叠,我希望反转图例,以便图更易于阅读。

我该怎么做?

【问题讨论】:

  • 您能否在您的主题中提供代码(不仅仅是屏幕)?

标签: python pandas legend legend-properties


【解决方案1】:

你可以在循环之前调用它:

 fig, ax = plt.subplots()

然后在绘图之前:

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles[::-1], labels[::-1])

正如here所说的那样。

【讨论】:

    猜你喜欢
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 2019-12-26
    • 2016-12-30
    • 1970-01-01
    • 2018-12-18
    • 1970-01-01
    相关资源
    最近更新 更多