Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

enter image description here

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.

like image 951
dino Avatar asked Feb 04 '17 00:02

dino


1 Answers

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

enter image description here

like image 125
ImportanceOfBeingErnest Avatar answered Sep 27 '22 22:09

ImportanceOfBeingErnest