簡體   English   中英

如何用Seaborn在hexbins上繪制回歸線?

[英]How to plot regression line on hexbins with 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'})

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的軸。 這是一個示例,包含一些補充數據:

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)

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM