如何在seaborn lmplot中标注回归线?

2024-09-23 22:28:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Seaborn中绘制了两个变量,并使用hue关键字将变量分为两类。在

我想用决定系数来注释每一条回归线。This question仅描述如何使用图例显示行的标签。在

 import pandas as pd 
 import seaborn as sns
 import matplotlib.pyplot as plt 

df = pd.read_excel(open('intubation data.xlsx', 'rb'), sheet_name='Data 
(pretest)', header=1, na_values='x')
vars_of_interest = ['PGY','Time (sec)','Aspirate (cc)']
df['Resident'] = df['PGY'] < 4

 lm = sns.lmplot(x=vars_of_interest[1], y=vars_of_interest[2],
        data=df, hue='Resident', robust=True, truncate=True,
        line_kws={'label':"bob"})

Tags: ofimporttruedfdataas绘制vars