python - 在 Seaborn PairGrid 中使用 lmplot

标签 python matplotlib seaborn scatter-plot lmplot

我试图绘制一个 PairGrid 在对角线上使用密度估计,在 上三角部分和下三角中的成对线性回归模型 部分。这是我的数据文件:

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'

最佳答案

您很可能需要 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

关于python - 在 Seaborn PairGrid 中使用 lmplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61599587/

相关文章:

Python Anaconda 错误 : NoPackagesFoundError: Packages missing in current win-64 channels:

Python:静态变量装饰器

python - 无法导入模块 'lambda_function' : cannot import name 'WinDLL' from 'ctypes' (/var/lang/lib/python3. 7/ctypes/__init__.py

python - 来自 basemap.Basemap 的分割错误

python - 在 seaborn Pairgrid 中绘制下三角

python - Seabornpairplot kde 对角线默认行为

python - 如何从 seaborn 的 KDE distplot 对象中提取垃圾箱?

python - 在Python中转换多维数组维度

python - 如何在 matplotlib 中用文本注释热图

python - Pyspark RDD 将当前行与下一行合并,直到当前行长度达到 x