根据对象在箱图中排序 [英] ordering in boxplot according to an object

查看:47
本文介绍了根据对象在箱图中排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在熊猫df中有一些分组的箱线图。

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

var2是一个对象,我想根据var2以字母顺序显示箱线图order

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)

无需手动放置:order = [ a, b, c, d, e]

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

推荐答案

不是100%确定需要排序的内容,但实际上您需要使用unique():

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)

这篇关于根据对象在箱图中排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆