Skip to content Skip to sidebar Skip to footer

Ordering Boxplot X-axis In Seaborn

My dataframe round_data looks like this: error username task_path 0 0.02 n49vq14uhvy93i5uw33tf7s1ei07vngozrzlsr6q6cnh8w...

Solution 1:

I figured out the answer:

grouped = round_data[round_data.batch==i].groupby('username')
users_sorted_average = (
    pd.DataFrame({col: vals['absolute_error'] for col, vals in grouped})
    .mean()
    .sort_values(ascending=True)
)

Passing users_sorted_average for the "order" parameter in the seaborn plot function would give the desired behavior:

ax = sns.boxplot(
    x='username', 
    y='error', 
    data=round_data, 
    whis=np.inf,
    ax=ax,
    color=c,
    order=users_sorted_average.index,
)

enter image description here


Post a Comment for "Ordering Boxplot X-axis In Seaborn"