ordering in boxplot according to an object

筅森魡賤 提交于 2019-12-04 06:15:01

问题


I would like to have some grouped boxplot in a pandas df.

var2 is an object, and I would like to display the boxplot in alphabetical order according to var2 order

import seaborn as sns
sns.set_style("whitegrid")   
ax = sns.boxplot(x="var1", y="var2",order=???, data=df)

without putting manually: order=["a","b","c","d","e"]


回答1:


Not 100% sure what needs to be sorted, but essentially you need to use unique():

order = sorted(df.var1.unique())
ax = sns.boxplot(x="var1", y="var2", order=order, data=df)


来源:https://stackoverflow.com/questions/38143927/ordering-in-boxplot-according-to-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!