ordering in boxplot according to an object

后端 未结 1 1840
遥遥无期
遥遥无期 2021-01-29 00:04

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

<
1条回答
  •  独厮守ぢ
    2021-01-29 00:50

    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)
    

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