Display bars in plot by ascending/descending order, Matplotlib, Python

Viewed 1645

I have a DataFrame with several numeric columns. My task is to display sums of each column in one chart. I decided to use import matplotlib as plt and a next code

df.sum().plot.bar(figsize = (10,5))
plt.xlabel('Category')
plt.ylabel('Sum')
plt.title('Mast popular categories')
plt.show()

I've got this pic

enter image description here

What I want to change here is to replace bars by ascending/descending order (for example from biggest bar to smallest). But I can't succeed. Help me please to solve this!

1 Answers

Sort the data before plot:

df.sum().sort_values(ascending=False).plot.bar(figsize = (10,5))
Related