Seaborn - grids and customization¶
In [4]:
Copied!
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
iris= sns.load_dataset('iris')
iris.head()
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
iris= sns.load_dataset('iris')
iris.head()
Out[4]:
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 |
In [6]:
Copied!
grd = sns.PairGrid(data=iris)
#then you can assign what you want plotted for diagonal, above diagonal, below diagonal.
# when mapping, pass just function pointers, dont call the function itself.
grd.map_diag(sns.distplot)
grd.map_upper(plt.scatter)
grd.map_lower(sns.kdeplot)
grd = sns.PairGrid(data=iris)
#then you can assign what you want plotted for diagonal, above diagonal, below diagonal.
# when mapping, pass just function pointers, dont call the function itself.
grd.map_diag(sns.distplot)
grd.map_upper(plt.scatter)
grd.map_lower(sns.kdeplot)
Out[6]:
<seaborn.axisgrid.PairGrid at 0x11ea36f98>
lmplot()
for scatter and regression per category¶
Sometimes, you need to do a joinplot()
but split it by some categorical column. You can custom build it using FacetGrid
shown in next section. However, seaborn provides a convenience function called lmplot()
. Note: In previous pages, you created lmplots()
for just 2 columns without any category.
In [330]:
Copied!
pgrid = sns.lmplot(x='min_season', y='min_pressure_merged',
col='any_basin', # the column by which you need to split - needs to be categorical
data=set1,
col_wrap=3, # number of columns per row
sharex=False, sharey=False, # will repeat ticks, coords for each plot
line_kws={'color':'green'} # symbol for regression line
)
pgrid = sns.lmplot(x='min_season', y='min_pressure_merged',
col='any_basin', # the column by which you need to split - needs to be categorical
data=set1,
col_wrap=3, # number of columns per row
sharex=False, sharey=False, # will repeat ticks, coords for each plot
line_kws={'color':'green'} # symbol for regression line
)