【问题标题】:Edit or remove facet labels of Seaborn displot编辑或删除 Seaborn displot 的构面标签
【发布时间】:2021-10-19 13:16:14
【问题描述】:

如果之前有人问过这个问题,我们深表歉意 - 有很多关于 seaborn 细节的问题:

我的问题是关于从 distplot 中删除构面标签。我觉得它们应该是情节对象的一个​​属性,但我不能完全挖掘/设置它们。也许我做错了。

我有一个多面直方图。但我计划将此作为许多情节之一,因此最终图像中没有足够的空间来包含其当前位置的刻​​面细节,因此我想将它们从子情节中删除。

代表

来自 seaborn distplot 文档。

import seaborn as sns

sns.set_theme(style="darkgrid")
df = sns.load_dataset("penguins")
sns.displot(
    df, x="flipper_length_mm", col="species", row="sex",
    binwidth=3, height=3, facet_kws=dict(margin_titles=True),
)

这会产生情节:

我想删除整个 species=... 方面。

【问题讨论】:

  • 您是指整个species = variable 还是只是species =
  • 整个标签 (species=variable)。我将编辑 q。

标签: python plot seaborn


【解决方案1】:

您可以使用方法sns.FacetGrid.set_titles 关闭(或更改其标签)列和行标题。

我会提醒您不要这样做,除非您设置 col_order 参数以便知道哪些轴属于每个特定变量。

import seaborn as sns

sns.set_theme(style="darkgrid")
df = sns.load_dataset("penguins")

g = sns.displot(
    df, x="flipper_length_mm", col="species", row="sex",
    binwidth=3, height=3, facet_kws=dict(margin_titles=True),
)
g.set_titles(col_template="")
# This will also remove the row labels
# g.set_titles(col_template="", row_template="")


当不使用margin_titles 时使用g.set_titles(template="") 将删除整个顶部标题。

【讨论】:

  • 太完美了。谢谢。这对于了解如何编辑行标签也很有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-08
  • 1970-01-01
  • 2016-12-13
  • 2013-07-19
  • 1970-01-01
  • 2018-01-14
  • 1970-01-01
相关资源
最近更新 更多