Manojit
Manojit

Reputation: 671

Making seaborn.PairGrid() look like pairplot()

In the example below, how do I use seaborn.PairGrid() to reproduce the plots created by seaborn.pairplot()? Specifically, I'd like the diagonal distributions to span the vertical axis. Markers with white borders etc... would be great too. Thanks!

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset('iris')

# pairplot() example
g = sns.pairplot(iris, kind='scatter', diag_kind='kde')
plt.show()

# PairGrid() example
g = sns.PairGrid(iris)
g.map_diag(sns.kdeplot)
g.map_offdiag(plt.scatter)
plt.show()

enter image description hereenter image description here

Upvotes: 2

Views: 1982

Answers (2)

mwaskom
mwaskom

Reputation: 49022

This is quite simple to achieve. The main differences between your plot and what pairplot does are:

  • the use of the diag_sharey parameter of PairGrid
  • using sns.scatterplot instead of plt.scatter

With that, we have:

iris = sns.load_dataset('iris')
g = sns.PairGrid(iris, diag_sharey=False)
g.map_diag(sns.kdeplot)
g.map_offdiag(sns.scatterplot)

enter image description here

Upvotes: 6

thorntonc
thorntonc

Reputation: 2126

To change the visual style:

import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset('iris')

g = sns.PairGrid(iris)
g.map_diag(sns.kdeplot, shade=True)
g.map_offdiag(plt.scatter, edgecolor="w")
plt.show()

enter image description here

Upvotes: 3

Related Questions