【问题标题】:How to set the of items in legend and plot with dataframe bar plot如何设置图例中的项目并使用数据框条形图进行绘图
【发布时间】:2021-02-05 20:01:54
【问题描述】:

我想改变下图中的条和图例的顺序。Bar plot

我想在图例中从上到下以及在情节中从左到右的顺序为高、中、低。这是我到目前为止的代码:

import numpy as np
import pandas as pd


index2 = ["1","2 ","3 ","4 ","5 ","6 "," 7 "]
df = pd.DataFrame({'High': High_distance,'Medium': Medium_distance,
                   'Low': Low_distance}, index=index2)


ax = df.plot.bar(rot=0)
plt.ylabel('distance',fontsize=30)
plt.xticks(fontsize=30)
plt.yticks(fontsize=30)
plt.legend(fontsize=25)



plt.show()

high_distance、medium_distance 和 low_distance 由 7 个元素组成。

【问题讨论】:

    标签: python dataframe bar-chart legend


    【解决方案1】:

    您可以指定列的顺序如下:

    ax = df[['High', 'Medium', 'Low']].plot.bar(rot=0)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-13
      • 2016-05-03
      • 2022-08-21
      • 2022-11-10
      相关资源
      最近更新 更多