微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何在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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。