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

我终于设法将我的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在hexbins上绘制回归线?

但是我希望在它上面覆盖一条回归线,并且无法弄清楚如何这样做.例如,当我将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)

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

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

解决方法:

您需要指定要显示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)

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

上一篇:python 3 pandas和seaborn使用swarmplot斗争 – multiIndex


下一篇:python – Seaborn pairplot和NaN值