Python Central HubSign in

Data Analytics with Python / Phase 6: Statistical Visualization with Seaborn

Pair Plots

Use pairplot to quickly explore relationships among multiple numeric variables with optional hue.

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.

diagram How pairplot fills a grid mermaid
pairplot builds an n×n grid: scatter plots off the diagonal, a distribution plot on the diagonal.

Basic pairplot

Python
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

Python
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",
)

Tips

  • Pair plots can be slow for large datasets. Sample rows if needed.
  • Use hue to check if groups separate naturally.

Check your understanding

quizCheck yourself
  1. What does sns.pairplot draw?

    Show answer

    B — A matrix of pairwise scatter plots with distributions on the diagonal — A pair plot is a scatter plot matrix, with each variable's distribution along the diagonal.

  2. Why add hue="species" to the penguins pairplot?

    Show answer

    C — To check whether groups separate naturally — Coloring by species shows whether groups form distinct clusters.

  3. The pairplot is slow on a very large dataset. What does the lesson advise?

    Show answer

    A — Sample rows — Many variables times many rows means many scatter plots, so sample rows first.

  4. Which option gives smooth curves on the diagonal?

    Show answer

    B — diag_kind="kde" — diag_kind="kde" replaces the diagonal histograms with density curves. plot_kws only styles the scatter plots.

Next

Continue to Facet Grids to split any plot type into small multiples by category.

🧪 Try It Yourself

Exercise 1 – A Basic Pair Plot

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Color by Species

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Use KDE on the Diagonal

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did