如何在Seaborn线性回归联合图中显示回归线

问题描述

seaborn API中所述,以下代码生成线性回归图。

import seaborn as sns 
import matplotlib.pyplot as plt 
  
# loading dataset 
penguins = sns.load_dataset("penguins")
  
# draw jointplot with reg kind 
sns.jointplot(data=penguins,x="bill_length_mm",y="bill_depth_mm",kind="reg")

This is the regression plot

不幸的是,没有回归线。如何在API添加一行?

解决方法

我也尝试使用regplot()

sns.regplot(x="bill_length_mm",y="bill_depth_mm",data=penguins)

但是它也没有显示行。但是,将其与jointplot结合使用:

sns.jointplot(data=penguins,x="bill_length_mm",kind="reg")
sns.regplot(x="bill_length_mm",data=penguins)

Post Authentication Lambda Trigger

,
 try JointGrid it combines two plots into one.  In this cat a regplot and a distplot.  The regplot shows the linear regression trend and the distplot shows the data distribution in one graph
 import scipy.stats as stats

 g=sns.JointGrid(data=df,y="bill_depth_mm")
 g.plot(sns.regplot,sns.distplot)

 or

 g=g.plot_joint(sns.kdeplot)
 g=g.plot_marginals(sns.kdeplot,shade=True)
 g=g.annotate(stats.pearsonr)