Seaborn pairplot off-diagonal KDE with two classes

狂风中的少年 提交于 2020-06-10 09:03:22

问题


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. 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. 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.


回答1:


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()



来源:https://stackoverflow.com/questions/42035284/seaborn-pairplot-off-diagonal-kde-with-two-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!