2016-11-09 114 views
2

我的数据框round_data看起来是这样的:订购箱线图x轴seaborn

 error       username     task_path 
0  0.02 n49vq14uhvy93i5uw33tf7s1ei07vngozrzlsr6q6cnh8w... 39.png 
1  0.10 n49vq14uhvy93i5uw33tf7s1ei07vngozrzlsr6q6cnh8w... 45.png 
2  0.15 n49vq14uhvy93i5uw33tf7s1ei07vngozrzlsr6q6cnh8w... 44.png 
3  0.25 xdoaztndsxoxk3wycpxxkhaiew3lrsou3eafx3em58uqth... 43.png 
...  ...            ...  ... 
1170 -0.11 9qrz4829q27cu3pskups0vir0ftepql7ynpn6in9hxx3ux... 33.png 
1171 0.15 9qrz4829q27cu3pskups0vir0ftepql7ynpn6in9hxx3ux... 34.png 


[1198 rows x 3 columns] 

我想有显示通过平均性能来分类的每个用户的错误的箱线图。我所拥有的是:

ax = sns.boxplot(x="username", y="error", data=round_data, 
       whis=np.inf, color="c",ax=ax) 

导致这个情节: boxplot

我如何排序的x轴(即用户)的平均误差?

回答

2

好吧,我想通了答案:

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) 

传递users_sorted_average为 “命令” 参数在seaborn绘图功能会得到期望的行为:

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