0% found this document useful (0 votes)
31 views

Using Facetgrid, Factorplot and Lmplot: Chris Mo

The document discusses various plots that can be created using the Seaborn library in Python. It introduces FacetGrid and factorplot for creating categorical plots. FacetGrid allows controlling how data is distributed across columns and rows. Factorplot combines facetting and mapping into one function. JointGrid and jointplot can be used to visualize the relationship between two variables, with JointGrid providing more control over the plots. PairGrid and pairplot are for exploring pairwise relationships between multiple variables. The document provides examples of creating these various types of plots using Seaborn.

Uploaded by

vrhdzv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Using Facetgrid, Factorplot and Lmplot: Chris Mo

The document discusses various plots that can be created using the Seaborn library in Python. It introduces FacetGrid and factorplot for creating categorical plots. FacetGrid allows controlling how data is distributed across columns and rows. Factorplot combines facetting and mapping into one function. JointGrid and jointplot can be used to visualize the relationship between two variables, with JointGrid providing more control over the plots. PairGrid and pairplot are for exploring pairwise relationships between multiple variables. The document provides examples of creating these various types of plots using Seaborn.

Uploaded by

vrhdzv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

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 Mo
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 = sns.FacetGrid(df, col="HIGHDEG")
g.map(sns.boxplot, '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 face ing and mapping process into 1 function

sns.factorplot(x="Tuition", data=df,
col="HIGHDEG", kind='box')

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


FacetGrid for regression
FacetGrid() can also be used for sca er or regression plots

g = sns.FacetGrid(df, col="HIGHDEG")
g.map(plt.scatter, 'Tuition', 'SAT_AVG_ALL')

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


lmplot
lmplot plots sca er and regression plots on a FacetGrid

sns.lmplot(data=df, x="Tuition", y="SAT_AVG_ALL",


col="HIGHDEG", fit_reg=False)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


lmplot with regression
sns.lmplot(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 Mo
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 = sns.PairGrid(df, vars=["Fair_Mrkt_Rent",
"Median_Income"])
g = g.map(plt.scatter)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Customizing the PairGrid diagonals
g = sns.PairGrid(df, vars=["Fair_Mrkt_Rent",
"Median_Income"])
g = g.map_diag(plt.hist)
g = g.map_offdiag(plt.scatter)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Pairplot
pairplot is a shortcut for the PairGrid

sns.pairplot(df, vars=["Fair_Mrkt_Rent",
"Median_Income"], kind='reg',
diag_kind='hist')

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Customizing a pairplot
sns.pairplot(df.query('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 Mo
Instructor
JointGrid() Overview

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Basic JointGrid
g = sns.JointGrid(data=df, x="Tuition",
y="ADM_RATE_ALL")
g.plot(sns.regplot, sns.distplot)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Advanced JointGrid
g = sns.JointGrid(data=df, x="Tuition",
y="ADM_RATE_ALL")
g = g.plot_joint(sns.kdeplot)
g = g.plot_marginals(sns.kdeplot, shade=True)
g = g.annotate(stats.pearsonr)

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


jointplot()
sns.jointplot(data=df, x="Tuition",
y="ADM_RATE_ALL", kind='hex')

INTERMEDIATE DATA VISUALIZATION WITH SEABORN


Customizing a jointplot
g = (sns.jointplot(x="Tuition",
y="ADM_RATE_ALL", kind='scatter',
xlim=(0, 25000),
marginal_kws=dict(
bins=15,rug=True),
data=df.query('UG < 2500 &
Ownership == "Public"'))
.plot_joint(sns.kdeplot))

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 Mo
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
face ing

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

You might also like