简体   繁体   English

订购 y 轴杆 plot asc 或 desc

[英]order y axis bar plot asc or desc

This code gives the plot underneath.此代码在下面给出 plot。 The plot is ordered alphabetical. plot 按字母顺序排列。 How can I make the Y axis ordered desc or asc based on value of x axis (x axis are euro's in this case).如何根据 x 轴的值(在这种情况下 x 轴是欧元)使 Y 轴有序 desc 或 asc。 Thanks!谢谢!

''' '''

df.groupby(['Type']).sum()['Bedrag'].plot.barh(y='Type');

''' '''

You can use the sort_values function:您可以使用sort_values function:

df.groupby(['Type']).sum()['Bedrag'].sort_values().plot.barh(y='Type')

You can pass the ascending parameter to specify if you want to sort asc or desc:您可以传递ascending参数来指定是否要按升序或降序排序:

...sort_values(ascending=True)
...sort_values(ascending=False)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM