在Seaborn PairGrid中使用lmplot

2024-06-17 08:32:20 发布

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

我正试图用对角线上的密度估计来绘制一个PairGrid图,图中的散点图 上三角部分和下三角部分的两两线性回归模型 部分这是我的dataftame:

df.head()

enter image description here 这是我的代码:

g = sns.PairGrid(df, hue="quality bin")
g = g.map_upper(sns.scatterplot)
g = g.map_lower(sns.lmplot)
g = g.map_diag(sns.kdeplot)
g = g.add_legend()

但是我得到了这个错误:TypeError: lmplot() got an unexpected keyword argument 'label'


Tags: 代码模型mapdf绘制线性huehead
1条回答
网友
1楼 · 发布于 2024-06-17 08:32:20

很有可能你需要sns.regplot(),我认为sns.lmplot()里面的方面把事情搞砸了。查看以下内容是否适用于您:

import pandas as pd
import seaborn as sns
df = pd.read_csv("wine_dataset.csv")
df.columns
df = df[['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar','quality']]
df['quality'] = ['high' if i > 5 else 'low' for i in df['quality']]
g = sns.PairGrid(df, hue="quality")
g = g.map_upper(sns.scatterplot)
g = g.map_lower(sns.regplot,scatter_kws = {'alpha': 0.1,'s':3})
g = g.map_diag(sns.kdeplot)
g = g.add_legend()

enter image description here

相关问题 更多 >