以下是我的小数据:
aa3=pd.DataFrame({'OfficeName':['Narre Warren','Cannington','Chadstone','1_Mean',
'Traralgon','Bondi Junction','Hobart','2_Mean'],
'Ratio':[0.1,0.2,0.4,0.1,0.43,0.4,0.15,0.32]})
官名的顺序正是我想要的。但是,当我尝试绘制条形图时:
plt.bar(aa3.loc[:,'OfficeName'],aa3.loc[:,'Ratio'])
图表如下所示:
可以看到x轴的顺序是自动改变的。这对我的工作真的不好。我应该怎么做才能让图表仅仅根据数据中的顺序显示条形图呢
请尝试以下代码:
所以我在这里对你的代码做了一点修改:
这将为您提供所需的输出:
有关更多信息,请参阅文档:https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.bar.html#pandas.DataFrame.plot.bar
相关问题 更多 >
编程相关推荐