Janneman
Janneman

Reputation: 353

order y axis bar plot asc or desc

This code gives the plot underneath. The plot is ordered alphabetical. 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). Thanks!

'''

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

'''

Upvotes: 0

Views: 128

Answers (1)

Bob
Bob

Reputation: 1070

You can use the 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:

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

Upvotes: 1

Related Questions