seaborn-ch中分类标签的分类

2024-05-14 20:10:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我确信这应该很容易,但是我在seaborn文档中找不到我如何特别地选择要显示的x标签分类变量的顺序?

我每周的工作时间如下所示,但我想在x轴上从0-10小时、11-20小时、21-30小时、31-40小时和40小时以上订购。我该怎么做?

def hours_per_week (x):
if x < 11: return '0-10 hours'
elif x < 21: return '11-20 hours'
elif x < 31: return '21-30 hours'
elif x < 41: return '31-40 hours'
else: return 'More than 40 hours'

这是我的海本代码来绘制图表。注:“收入类别”是指收入低于5万的人群和收入高于5万的人群

plot_income_cat_hours = sns.countplot(x='hours_per_week_grouping',
                                      hue='income-cat', data=data)

这是我的绘图当前的外观(由于不相关,上面的代码中没有包含一些其他格式): enter image description here


Tags: 代码文档datareturn分类标签seaborncat
1条回答
网友
1楼 · 发布于 2024-05-14 20:10:05

试试这个:

plot_income_cat_hours = sns.countplot(x='hours_per_week_grouping',
                        hue='income-cat', data=data,order=['place the desired order here'])

相关问题 更多 >

    热门问题