我想在pandas df中有一些分组的箱形图。
var2是一个对象,我想根据var2顺序按字母顺序显示boxplot
import seaborn as sns
sns.set_style("whitegrid")
ax = sns.boxplot(x="var1", y="var2",order=???, data=df)
无需手动输入:order = [" a"," b"," c"," d"," E"]
答案 0 :(得分:2)
不是100%确定需要排序的内容,但基本上你需要使用unique():
order = sorted(df.var1.unique())
ax = sns.boxplot(x="var1", y="var2", order=order, data=df)