question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

countplot does not have option for the ordering of the x values

See original GitHub issue

The count plot function does not have any way to order the values. The default ordering of x is incorrect.

I used the following code:

ax = sns.countplot(x=("PhdDecade", "first"),
                 data=df_faculty, color="grey")
for p in ax.patches:
    height = p.get_height()
    ax.text(p.get_x()+0.25, height+ 3, 'n=%.0f'%(height))

image

Seaborn version: 0.7.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
adicostilcommented, Nov 7, 2017

try this, should be desc by counts

ax = sns.countplot(x=("PhdDecade", "first"),
                 data=df_faculty, color="grey", order=df_faculty['PhdDecade'].value_counts().index)

if you need asc

order=reversed(df_faculty['PhdDecade'].value_counts().index)
1reaction
JRSamicommented, Nov 15, 2021

Also, might try:

df_faculty[‘PhdDecade’] = pd.Categorical(df_faculty[‘PhdDecade’], categories = [‘1950’s’,‘1960’s’,‘1970’s’,‘1980’s’,‘1990’s’,‘2000’s’,‘2010’s’], ordered = True)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Seaborn.countplot : order categories by count - Stack Overflow
countplot as far as I know - the order parameter only accepts a list of strings for the categories, and leaves the ordering...
Read more >
seaborn.countplot — seaborn 0.12.1 documentation - PyData |
A count plot can be thought of as a histogram across a categorical, instead of quantitative, variable. The basic API and options are...
Read more >
Seaborn countplot: set order, size, palette and values
Create a Seaborn countplot using Python: a step by step example ... As you can see above, the current order of the x-axis...
Read more >
Countplot using seaborn in Python - GeeksforGeeks
countplot () method is used to Show the counts of observations in each categorical bin using bars. Syntax : seaborn.countplot(x=None, y=None, hue ...
Read more >
sns.countplot order - Mj Cheruiyot - Medium
seaborn.countplot (*, x=None, y=None, hue=None, data=None, order=None, ... Your tip will go to Mj Cheruiyot through a third-party platform of their choice, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found