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

sam*_*and 5 python matplotlib seaborn

我终于设法将我的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'})
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)

在边缘情节中重新绘制

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

jak*_*vdp 5

您需要指定要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)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述