Grids

In [1]:
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
iris = sns.load_dataset('iris')
In [3]:
iris.head()
Out[3]:
sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 0.2 setosa
1 4.9 3.0 1.4 0.2 setosa
2 4.7 3.2 1.3 0.2 setosa
3 4.6 3.1 1.5 0.2 setosa
4 5.0 3.6 1.4 0.2 setosa

PairGrid

Pairgrid is a subplot grid for plotting pairwise relationships in a dataset.

In [4]:
# Just the Grid
sns.PairGrid(iris)
Out[4]:
<seaborn.axisgrid.PairGrid at 0x9dc3d30>
In [5]:
# Then you map to the grid
g = sns.PairGrid(iris)
g.map(plt.scatter)
Out[5]:
<seaborn.axisgrid.PairGrid at 0xb4100f0>
In [6]:
# Map to upper,lower, and diagonal
g = sns.PairGrid(iris)
g.map_diag(plt.hist)
g.map_upper(plt.scatter)
g.map_lower(sns.kdeplot)
C:\ProgramData\Anaconda3\lib\site-packages\scipy\stats\stats.py:1713: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval
Out[6]:
<seaborn.axisgrid.PairGrid at 0xba766d8>

pairplot

pairplot is a simpler version of PairGrid (you'll use quite often)

In [15]:
# Will get to know abou all arguments
sns.pairplot?
In [7]:
sns.pairplot(iris)
Out[7]:
<seaborn.axisgrid.PairGrid at 0xca31e80>
In [8]:
sns.pairplot(iris,hue='species',palette='rainbow')
Out[8]:
<seaborn.axisgrid.PairGrid at 0xd812a58>

Facet Grid

FacetGrid is the general way to create grids of plots based off of a feature:

In [9]:
tips = sns.load_dataset('tips')
In [10]:
tips.head()
Out[10]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
In [11]:
# Just the Grid
g = sns.FacetGrid(tips, col="time", row="smoker")
In [12]:
g = sns.FacetGrid(tips, col="time",  row="smoker")
g = g.map(plt.hist, "total_bill")
In [13]:
g = sns.FacetGrid(tips, col="time",  row="smoker",hue='sex')
# Notice hwo the arguments come after plt.scatter call
g = g.map(plt.scatter, "total_bill", "tip").add_legend()

JointGrid

JointGrid is the general version for jointplot() type grids, for a quick example:

In [14]:
g = sns.JointGrid(x="total_bill", y="tip", data=tips)
In [45]:
g = sns.JointGrid(x="total_bill", y="tip", data=tips)
g = g.plot(sns.regplot, sns.distplot)
/Users/marci/anaconda/lib/python3.5/site-packages/statsmodels/nonparametric/kdetools.py:20: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
  y = X[:m/2+1] + np.r_[0,X[m/2+1:],0]*1j

Happy Learning..!