【发布时间】:2020-11-25 22:13:07
【问题描述】:
我在 Seaborn 中创建了以下情节:
ax = sns.factorplot(x='metric', y='number', hue='drop', data=df, kind='bar')
plt.legend(loc='best')
plt.subplots_adjust(top=.925)
ax._legend.remove()
sns.despine(ax=ax)
plt.show()
但是,这会引发错误:
AttributeError: 'FacetGrid' object has no attribute 'spines'
我需要将刺变白或移除它们,你如何为 factorplot/FacetGrid 做到这一点?
【问题讨论】:
-
factorplot返回一个 FacetGrid,而不是 Axes 对象,所以我将其称为fg而不是ax。然后我会做despine(fig=fg.fig) -
嗨@PaulH,不幸的是,这不起作用,我完全按照你的建议做了,但我不得不写 sns.despine(fig=fg.fig)。它没有移除轴,但没有出错。我错过了什么吗?
-
您要移除哪些刺?默认情况下仅移除左侧和顶部
-
我想去掉左边和底部(左边目前没有被去掉)
标签: matplotlib plot bar-chart seaborn visualization