Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'}

It seems to just order the columns by the order that they appear in. How can I change the order to 'Sun'...'Sat' instead?

enter image description here

like image 561
Austin Avatar asked Dec 19 '22 08:12

Austin


2 Answers

You can use the order parameter of countplot like this:

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

where DOW is my dayofweek column.

I also noticed that by not mentioning a day, you can omit that day being displayed in the chart.

like image 181
HauntedBaker Avatar answered Jan 09 '23 18:01

HauntedBaker


figured it out:

k = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
dayWeek = sorted(dayWeek, key=k.index)
like image 32
Austin Avatar answered Jan 09 '23 18:01

Austin