如何在seaborn.lmplot中为整个数据添加回归线?

Aki*_*ira 0 matplotlib python-3.x seaborn

我正在尝试绘制散点图,其中每个点都根据变量进行着色Points。此外,我想添加回归线。

import pandas as pd
import urllib3
import seaborn as sns

decathlon = pd.read_csv("https://raw.githubusercontent.com/leanhdung1994/Deep-Learning/main/decathlon.txt", sep='\t')

g = sns.lmplot(
    data = decathlon,
    x="100m", y="Long.jump",
    hue = 'Points', palette = 'viridis'
)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

在我看来,有两条回归线,每组数据各一条。这不是我想要的。我想要整个数据的回归线。此外,如何隐藏右侧的图例?

您能否详细说明一下如何操作?

Diz*_*ahi 6

lmplot除非您需要使用 aFacetGrid将数据集拆分为多个子图,否则不应使用。

由于您显示的示例未使用 提供的任何功能,因此您应该使用和 的FacetGrid组合来创建绘图scatterplot()regplot()

tips = sns.load_dataset('tips')
ax = sns.scatterplot(data=tips, x="total_bill", y="tip", hue="day")
sns.regplot(data=tips, x="total_bill", y="tip", scatter=False, ax=ax)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述