我正在尝试绘制散点图,其中每个点都带有变量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'
)
在我看来,有2条回归线,每组数据对应一条。这不是我想要的。我想对整个数据使用回归线。此外,如何隐藏图例的右侧?
您能否详细说明如何做?
答案 0 :(得分:1)
除非应该使用FacetGrid
将数据集划分为多个子图,否则不应使用lmplot
。
由于显示的示例未使用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)