Using FacetGrid,
factorplot and lmplot
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Chris Mof tt
Instructor
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Tidy data
Seaborn's grid plots require data in "tidy format"
One observation per row of data
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
FacetGrid
The FacetGrid is foundational for many data aware grids
It allows the user to control how data is distributed across columns,
rows and hue
Once a FacetGrid is created, the plot type must be mapped to
the grid
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
FacetGrid Categorical Example
g = [Link](df, col="HIGHDEG")
[Link]([Link], 'Tuition',
order=['1', '2', '3', '4'])
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
factorplot()
The factorplot is a simpler way to use a FacetGrid for
categorical data
Combines the facetting and mapping process into 1 function
[Link](x="Tuition", data=df,
col="HIGHDEG", kind='box')
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
FacetGrid for regression
FacetGrid() can also be used for scatter or regression plots
g = [Link](df, col="HIGHDEG")
[Link]([Link], 'Tuition', 'SAT_AVG_ALL')
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
lmplot
lmplot plots scatter and regression plots on a FacetGrid
[Link](data=df, x="Tuition", y="SAT_AVG_ALL",
col="HIGHDEG", fit_reg=False)
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
lmplot with regression
[Link](data=df, x="Tuition", y="SAT_AVG_ALL",
col="HIGHDEG", row='REGION')
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Let's practice!
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Using PairGrid and
pairplot
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Chris Mof tt
Instructor
Pairwise relationships
PairGrid shows pairwise relationships between data elements
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Creating a PairGrid
The PairGrid follows similar API to FacetGrid
g = [Link](df, vars=["Fair_Mrkt_Rent",
"Median_Income"])
g = [Link]([Link])
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Customizing the PairGrid diagonals
g = [Link](df, vars=["Fair_Mrkt_Rent",
"Median_Income"])
g = g.map_diag([Link])
g = g.map_offdiag([Link])
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Pairplot
pairplot is a shortcut for the PairGrid
[Link](df, vars=["Fair_Mrkt_Rent",
"Median_Income"], kind='reg',
diag_kind='hist')
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Customizing a pairplot
[Link]([Link]('BEDRMS < 3'),
vars=["Fair_Mrkt_Rent",
"Median_Income", "UTILITY"],
hue='BEDRMS', palette='husl',
plot_kws={'alpha': 0.5})
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Let's practice!
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Using JointGrid and
jointplot
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Chris Mof tt
Instructor
JointGrid() Overview
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Basic JointGrid
g = [Link](data=df, x="Tuition",
y="ADM_RATE_ALL")
[Link]([Link], [Link])
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Advanced JointGrid
g = [Link](data=df, x="Tuition",
y="ADM_RATE_ALL")
g = g.plot_joint([Link])
g = g.plot_marginals([Link], shade=True)
g = [Link]([Link])
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
jointplot()
[Link](data=df, x="Tuition",
y="ADM_RATE_ALL", kind='hex')
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Customizing a jointplot
g = ([Link](x="Tuition",
y="ADM_RATE_ALL", kind='scatter',
xlim=(0, 25000),
marginal_kws=dict(
bins=15,rug=True),
data=[Link]('UG < 2500 &
Ownership == "Public"'))
.plot_joint([Link]))
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Customizing a jointplot
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Let's practice!
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Selecting Seaborn
Plots
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N
Chris Mof tt
Instructor
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Univariate Distribution Analysis
distplot() is the best place to start for this analysis
rugplot() and kdeplot() can be useful alternatives
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Regression Analysis
lmplot() performs regression analysis and supports facetting
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Categorical Plots
Explore data with the categorical plots and facet with
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
pairplot() and jointplot()
Perform regression analysis with lmplot
Analyze distributions with distplot
INTERMEDIATE DATA VISUALIZATION WITH SEABORN
Thank You!
I N T E R M E D I AT E D ATA V I S U A L I Z AT I O N W I T H S E A B O R N