- The correct way to set the xticklabels for
sns.catplot, according to the documentation, is with the.set_xticklabelsmethod (.e.g.g.set_xticklabels(rotation=30)). - Using a loop to iterate through the
Axes, should be used if changes need to be made on a plot by plot basis, within theFacetGrid. - Building structured multi-plot grids
seaborn.FacetGridgor in the case of the OP,axis aseaborn.axisgrid.FacetGrid- When iterating through
ax.axes.flat,axesis a<class 'matplotlib.axes._subplots.AxesSubplot'>, which has a wide array of class methods, including.get_xticklabels().
- When iterating through
import seaborn as sns
# load data
exercise = sns.load_dataset("exercise")
# plot catplot
g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=exercise)
# set rotation
g.set_xticklabels(rotation=30)
- Using
g.set_xticklabels(g.get_xticklabels(), rotation=30)results in anAttributeError.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-442-d1d39d8cc4f0> in <module>
1 g = sns.catplot(x="time", y="pulse", hue="kind", col="diet", data=exercise)
----> 2 g.set_xticklabels(g.get_xticklabels(), rotation=30)
AttributeError: 'FacetGrid' object has no attribute 'get_xticklabels'
1
solved How to rotate xticklabels in a seaborn catplot
