[英]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.