【问题标题】:How do you despine a facetgrid in Seaborn?你如何在 Seaborn 中鄙视 facetgrid?
【发布时间】: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


【解决方案1】:

下面这行可以替换

sns.despine(ax=ax)

ax.despine(left=True, bottom=True)

注意:名称ax 具有误导性,grid 更能说明它是什么(FacetGrid 对象)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-02
    • 2016-09-21
    • 1970-01-01
    • 2018-02-25
    • 2017-05-19
    • 2017-09-29
    • 1970-01-01
    相关资源
    最近更新 更多