I created a bar plot using matplotlib.pyplot and seaborn libraries. How can I sort bars in increasing order according to Speed
? I want to see the bars with the
df.groupby(['Id']).median().sort_values("Speed").plot.bar()
Or just try to sort_values("Speed") after you aggregate them.
EDIT: so you need to do this:
result = a.groupby(["Id"])['Speed'].aggregate(np.median).reset_index().sort_values('Speed')
and in sns.barplot add order:
sns.barplot(x='Id', y="Speed", data=a, palette=colors, order=result['Id'])