Ordering boxplot x-axis in seaborn

后端 未结 1 665
我在风中等你
我在风中等你 2021-02-05 16:19

My dataframe round_data looks like this:

      error                         username                    task_path
0      0.02  n49vq14uhvy93i5uw33t         


        
相关标签:
1条回答
  • 2021-02-05 17:22

    ok, 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)
    

    0 讨论(0)
提交回复
热议问题