【问题标题】:Using different axis scales in seaborn replot在 seaborn 重绘中使用不同的轴比例
【发布时间】:2019-06-03 13:35:13
【问题描述】:

我使用Seaborn documentation 中的这个示例来生成下图。

import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.relplot(x="total_bill", y="tip", hue="day", col="time", data=tips)

如何强制 x 轴或 y 轴使用不同的比例(例如,右侧子图中的 x 范围为 (0, 100))?

我尝试将 sharex=False 传递给 replot 函数,但这不是一个有效的关键字。

【问题讨论】:

    标签: matplotlib seaborn


    【解决方案1】:

    您需要使用facet_kws= 将参数传递给FacetGrid 对象。然后,您可以通过使用 g.axes 引用每个 Axes 来更改限制,g.axes 是 Axes 对象的二维数组。

    import seaborn as sns
    tips = sns.load_dataset("tips")
    g = sns.relplot(x="total_bill", y="tip", hue="day", col="time", data=tips, facet_kws=dict(sharex=False))
    g.axes[0,0].set_xlim(0,100)
    g.axes[0,1].set_xlim(20,30)
    

    【讨论】:

      猜你喜欢
      • 2020-10-10
      • 2018-10-23
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 1970-01-01
      相关资源
      最近更新 更多