简体   繁体   English

Seaborn pairplot非对角线KDE有两个类

[英]Seaborn pairplot off-diagonal KDE with two classes

I'm trying to look at a Seaborn pairplot for two different classes of variables and I'd like to see KDEs on the offdiagonals instead of scatterplots. 我正在尝试查看两个不同类变量的Seaborn配对图,我希望在offdiagonals上看到KDE而不是散点图。 The documentation has instructions on how to do a KDE for all of the data , but I want to see separate KDEs for each subclass of data. 该文档提供了有关如何为所有数据执行KDE的说明 ,但我希望为每个子类的数据看到单独的KDE。 Suggestions welcome! 建议欢迎!

My code looks something like this: 我的代码看起来像这样:

plot = sns.pairplot(
    df,
    vars=labels,
    hue='has_accident',
    palette='Set1',
    diag_kind='kde',
)

which results in: 这导致:

在此输入图像描述

As you can see the data are sufficiently dense that it is difficult to see the difference in the red and blue data on the off diagonal. 如您所见,数据足够密集,很难看到对角线上红色和蓝色数据的差异。

You possibly mean something like this: 你可能意思是这样的:

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

g = sns.PairGrid(iris, hue="species", hue_kws={"cmap": ["Blues", "Greens", "Reds"]})
g = g.map_diag(sns.kdeplot, lw=3)
g = g.map_offdiag(sns.kdeplot, lw=1)

plt.show()

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM