Rotate xtick labels in a marine crate box?

I have a question that is basically the same as a question from 2014 (see here ). However, my script is still throwing an error.

Here's what I'm doing: I have a pandas dataframe with multiple columns. I am drawing a simple box comparison.

g = sns.boxplot(x='categories', y='oxygen', hue='target', data=df)
g.set_xticklabels(rotation=30)

      

The graph looks like this:

enter image description here

I would like to rotate the x-marks by 30 degrees. So I am using g.set_xticklabels(rotation=30)

. However, I am getting the following error:

set_xticklabels() missing 1 required positional argument: 'labels'

I don't know how to pass an argument matplotlib

labels

to seaborns sns.boxplot

. Any ideas?

+3


source to share


1 answer


The question you linked uses factorplot

. Factplot returns its own class, which has a method set_xticklabels(rotation)

. This is different from the set_xticklabels

matplotlib method Axes

.

There are also other options in the linked Q&A that you can use

ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df)
ax.set_xticklabels(ax.get_xticklabels(),rotation=30)

      



or

ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df)
plt.setp(ax.get_xticklabels(), rotation=45)

      

+8


source







All Articles