简体   繁体   English

seaborn.countplot的订购轴

[英]Ordering axis of seaborn.countplot

I'm plotting day of week frequencies from a list of strings dayWeek , where set(dayWeek) = {'Mon', 'Sun', 'Tue', 'Sat', 'Fri', 'Wed', 'Thu'} 我正在从字符串dayWeek列表中绘制星期几频率,其中set(dayWeek) = {'Mon', 'Sun', 'Tue', 'Sat', 'Fri', 'Wed', 'Thu'}

It seems to just order the columns by the order that they appear in. How can I change the order to 'Sun'...'Sat' instead? 似乎只是按照列的显示顺序对其进行排序。如何将顺序更改为'Sun'...'Sat'

在此处输入图片说明

figured it out: 弄清楚了:

k = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
dayWeek = sorted(dayWeek, key=k.index)

You can use the order parameter of countplot like this: 您可以使用countplot的order参数,如下所示:

sns.countplot(y='DOW',order=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'], data=df, palette='viridis')

where DOW is my dayofweek column. DOW是我的“ dayofweek专栏。

I also noticed that by not mentioning a day, you can omit that day being displayed in the chart. 我还注意到,通过不提及日期,您可以省略图表中显示的那一天。

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

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