如何用Seaborn在hexpins上绘制回归线?

2024-10-01 07:47:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我终于设法把我的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时,回归线似乎占据了边缘图:

^{pr2}$

regplot in marginal plot

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


Tags: importasseabornreqwordcountreqsapplysns
1条回答
网友
1楼 · 发布于 2024-10-01 07:47:51

您需要指定希望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

相关问题 更多 >