gpt4 book ai didi

matplotlib - 在seaborn replot中使用不同的轴尺度

转载 作者:行者123 更新时间:2023-12-04 14:45:53 26 4
gpt4 key购买 nike

我使用了来自 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)

enter image description here

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

我试过了 sharex=False到 replot 函数,但这不是有效的关键字。

最佳答案

您需要使用 facet_kws=将参数传递给 FacetGrid目的。然后,您可以通过使用 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)

enter image description here

关于matplotlib - 在seaborn replot中使用不同的轴尺度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56428512/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com