Skip to content Skip to sidebar Skip to footer

How To Improve This Seaborn Countplot?

I used the following code to generate the countplot in python using seaborn: sns.countplot( x='Genres', data=gn_s) But I got the following output: I can't see the items on x-axis

Solution 1:

You can use choose the x-axis to be vertical, as an example:

g = sns.countplot( x='Genres', data=gn_s)
g.set_xticklabels(g.get_xticklabels(),rotation=90)

Or, you can also do:

plt.xticks(rotation=90)

Solution 2:

Bring in matplotlib to set up an axis ahead of time, so that you can modify the axis tick labels by rotating them 90 degrees and/or changing font size. To arrange your samples in order, you need to modify the source. I assume you're starting with a pandas dataframe, so something like:

data = data.sort_values(by='Genres', ascending=False) labels = # list of labels in the correct order, probably your data.index fig, ax1 = plt.subplots(1,1) sns.countplot( x='Genres', data=gn_s, ax=ax1) ax1.set_xticklabels(labels, rotation=90)

would probably help.

edit Taking andrewnagyeb's suggestion from the comments to order the plot:

sns.countplot( x='Genres', data=gn_s, order = gn_s['Genres'].value_counts().index)


Post a Comment for "How To Improve This Seaborn Countplot?"