简体   繁体   English

重新排列 seaborn countplot x 轴

[英]Rearrange seaborn countplot x-axis

I am using seaborn countplot on a pandas data series.我在 pandas 数据系列上使用 seaborn 计数图。 The series looks like this:该系列看起来像这样:

df['col'] = 

['Week 4',
 'Week 4',
 'Week 3',
 'Week 1',
 'Week 5',
 'Week 3',
 'Week 3',
 'Week 2',
 'Week 4',
 'Week 5',
 'Week 5',
 'Week 4',
 'Week 5',
 'Week 2',
 'Week 5',
 'Week 1',
 ..
 ..
 ..
 ..
]

I'd like rearrange the x-axis to start with Week 1, Week 2, Week 3.... and so on.我想重新排列 x 轴,从第 1 周、第 2 周、第 3 周开始……等等。

sns.countplot(LeaseComp['Weeks on market'])

在此处输入图像描述

You can sorted values like:您可以对值进行排序,例如:

L = ['Week 4',
 'Week 4',
 'Week 3',
 'Week 1',
 'Week 5',
 'Week 3',
 'Week 3',
 'Week 2',
 'Week 4',
 'Week 5',
 'Week 5',
 'Week 4',
 'Week 5',
 'Week 2',
 'Week 5',
 'Week 1',

]
LeaseComp = pd.DataFrame(L, columns=['Weeks on market'])

sns.countplot(LeaseComp['Weeks on market'].sort_values())

G

For seaborn:对于 seaborn:

sns.countplot( x = 'Weeks on market', data = LeaseComp, 
              order = sorted(LeaseComp['Weeks on market'].unique()))

Same plot can be achieved by what BEATHUB has posted, but it may produce some warnings. BEATHUB 发布的内容可以实现相同的 plot,但它可能会产生一些警告。

You may try,你可以试试,

sns.countplot(x= LeaseComp['Weeks on market'].sort_values())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM