-
设置xticklabels的正确方法
sns.catplot
根据文件,是与
.set_xticklabels
方法(.例如。
g.set_xticklabels(rotation=30)
).
-
使用循环迭代
Axes
如果需要逐点进行更改,则应在
FacetGrid
.
-
Building structured multi-plot grids
-
seaborn.FacetGrid
-
g
ax
是一个
seaborn.axisgrid.FacetGrid
-
迭代时
ax.axes.flat
,
axes
<class 'matplotlib.axes._subplots.AxesSubplot'>
.get_xticklabels()
.
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)
-
使用
g.set_xticklabels(g.get_xticklabels(), rotation=30)
AttributeError
.
---------------------------------------------------------------------------
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'