Grids

Grids are general types of plots that allow you to map plot types to rows and columns of a grid, this helps you create similar plots separated by features.


In [22]:
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline

In [27]:
iris = sns.load_dataset('iris')

In [28]:
iris.head()


Out[28]:
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 [25]:
# Just the Grid
sns.PairGrid(iris)


Out[25]:
<seaborn.axisgrid.PairGrid at 0x11e39bb38>

In [26]:
# Then you map to the grid
g = sns.PairGrid(iris)
g.map(plt.scatter)


Out[26]:
<seaborn.axisgrid.PairGrid at 0x11f431208>

In [30]:
# 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)


Out[30]:
<seaborn.axisgrid.PairGrid at 0x121944128>

pairplot

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


In [31]:
sns.pairplot(iris)


Out[31]:
<seaborn.axisgrid.PairGrid at 0x12024b5c0>

In [33]:
sns.pairplot(iris,hue='species',palette='rainbow')


Out[33]:
<seaborn.axisgrid.PairGrid at 0x12633f0f0>

Facet Grid

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


In [34]:
tips = sns.load_dataset('tips')

In [35]:
tips.head()


Out[35]:
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 [36]:
# Just the Grid
g = sns.FacetGrid(tips, col="time", row="smoker")



In [37]:
g = sns.FacetGrid(tips, col="time",  row="smoker")
g = g.map(plt.hist, "total_bill")



In [42]:
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 [43]:
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

Reference the documentation as necessary for grid types, but most of the time you'll just use the easier plots discussed earlier.

Great Job!