Seaborn Bar Plot Ordering

you can use the order parameter for this.

sns.barplot(x='Id', y="Speed", data=df, order=result['Id'])

Credits to Wayne.

See the rest of his code.

This link is still working for me. But, for the sake of convenience, I’m pasting the author’s code here.

result = df.groupby(["Id"])['Speed'].aggregate(np.median).reset_index().sort_values('Speed')
sns.barplot(x='Id', y="Speed", data=df, order=result['Id'])
plt.show()

df

   Id  Speed
0   1     30
1   1     35
2   1     31
3   2     20
4   2     25

result

   Id   Speed
1   2   22.5
0   1   31.0
2   3   80.0

Leave a Comment