Pair Plots
Why pair plots?
Section titled “Why pair plots?”Pair plots are a fast way to inspect:
- Pairwise relationships between variables
- Distributions on the diagonal
- Group separation using
hue
They are great early in EDA.
flowchart TD A["n numeric columns"] --> B["Build an n x n grid"] B --> C["Off-diagonal cells:
scatter of column i vs j"] B --> D["Diagonal cells:
histogram or KDE of column i"]
Basic pairplot
Section titled “Basic pairplot”import seaborn as sns
penguins = sns.load_dataset("penguins").dropna()
sns.pairplot(penguins[[
"bill_length_mm",
"bill_depth_mm",
"flipper_length_mm",
"body_mass_g",
]])Pairplot with hue
Section titled “Pairplot with hue”import seaborn as sns
penguins = sns.load_dataset("penguins").dropna()
sns.pairplot(
penguins,
vars=["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"],
hue="species",
)- Pair plots can be slow for large datasets. Sample rows if needed.
- Use
hueto check if groups separate naturally.
Continue to Facet Grids to split any plot type into small multiples by category.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – A Basic Pair Plot
Section titled “Exercise 1 – A Basic Pair Plot”Exercise 2 – Color by Species
Section titled “Exercise 2 – Color by Species”Exercise 3 – Use KDE on the Diagonal
Section titled “Exercise 3 – Use KDE on the Diagonal”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading