如何用Seaborn在六边形上绘制回归线? [英] How to plot regression line on hexbins with Seaborn?

查看:26
本文介绍了如何用Seaborn在六边形上绘制回归线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've finally managed to wrangle my hexbin distribution plot into something almost pretty.

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'})

但我希望在它上面叠加一条回归线,但不知道如何做到这一点.例如,当我在代码中添加 regplot 时,回归线似乎占据了边缘图:

But I'm hoping to overlay a regression line on top of it, and can't figure out how to do so. For instance, the regression line seems to occupy the marginal plot when I add regplot to the code:

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)

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

How to include the regression line in the body of the chart?

推荐答案

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

You need to specify the axes you want the regplot to appear on. Here is an example, with some made-up data:

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在六边形上绘制回归线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆