gpt4 book ai didi

python - 如何使用 Seaborn 在 hexbins 上绘制回归线?

转载 作者:太空狗 更新时间:2023-10-30 01:07:07 25 4
gpt4 key购买 nike

我终于设法将我的 hexbin 分布图整理成几乎漂亮的东西。

import seaborn as sns

x = req.apply_clicks
y = req.reqs_wordcount

sns.jointplot(x, y, kind="hex", color="#5d5d60",
joint_kws={'gridsize':40, 'bins':'log'})

Seaborn Hexbin

但我希望在其上覆盖一条回归线,但不知道该怎么做。例如,当我将 regplot 添加到代码中时,回归线似乎占据了边缘图:

x = req.apply_clicks
y = req.reqs_wordcount
z = sns.jointplot(x, y, kind="hex", color="#5d5d60",
joint_kws={'gridsize':40, 'bins':'log'})
sns.regplot(x, y, data=z, color="#5d5d60", scatter=False)

regplot in marginal plot

如何在图表主体中包含回归线?

最佳答案

您需要指定要显示 regplot 的轴。这是一个示例,其中包含一些虚构的数据:

import seaborn as sns
import numpy as np

x = 0.3 + 0.3 * np.random.randn(10000)
y = 0.1 - 0.2 * x + 0.1 * np.random.randn(10000)
mask = (y > 0) & (x > 0)
x, y = x[mask], y[mask]

g = sns.jointplot(x, y, kind="hex", color="#5d5d60",
joint_kws={'gridsize':40, 'bins':'log'})
sns.regplot(x, y, ax=g.ax_joint, scatter=False)

enter image description here

关于python - 如何使用 Seaborn 在 hexbins 上绘制回归线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33288830/

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