How to build a regression line on hexagons using Seaborn?

I finally managed to interrupt my hexbin distribution schedule into something almost beautiful.

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

But I hope to draw a regression line on top of it and I can’t figure out how to do it. For example, the regression line seems to occupy a marginal graph 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) 

regplot in a marginal plot

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

+3
source share
1 answer

You need to specify the axes in which you want to include regplot . Here is an example with some compiled 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) 

enter image description here

+4
source

Source: https://habr.com/ru/post/1211445/


All Articles