【问题标题】:Seaborn FacetGrid, how to show y tick labels in all subplots [duplicate]Seaborn FacetGrid,如何在所有子图中显示 y 刻度标签 [重复]
【发布时间】:2021-05-04 18:18:18
【问题描述】:

在 Seaborn FacetGrid 中,无论是否sharey=True,如何让 y 轴刻度标签显示在所有子图中?

tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time",  row="sex")
g.map(sns.scatterplot, "total_bill", "tip")

以下尝试返回错误AttributeError: 'FacetGrid' object has no attribute 'flatten'

for axis in g.flatten():
    for tick in axis.get_yticklabels():
        tick.set_visible(True)

【问题讨论】:

    标签: python seaborn facet-grid


    【解决方案1】:
    for axis in g.axes.flat:
        axis.tick_params(labelleft=True)
    

    这对我有用。

    【讨论】:

    【解决方案2】:
    for axis in axes.flatten():
        for tick in axis.get_yticklabels():
            tick.set_visible(True)
    

    尝试遍历每个绘图的每个轴并手动强制刻度标签可见。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-27
      • 1970-01-01
      • 2019-02-10
      • 1970-01-01
      • 2020-12-21
      • 2022-01-12
      • 2020-12-24
      • 2021-11-17
      相关资源
      最近更新 更多