Pair Plot

A pair plot (or scatterplot matrix) plots every numeric variable in a dataset against every other one, arranged in a grid - giving a fast, comprehensive first look at relationships across an entire dataset during exploratory data analysis.

What a Pair Plot Shows

  • Off-diagonal cells - scatter plots between each pair of variables
  • Diagonal cells - a histogram or density plot of each individual variable
  • Hue grouping - color-coding points by a categorical column to reveal class separation

Plotting with Seaborn

import seaborn as sns

sns.pairplot(df, hue="species")

Why Use It During EDA

Instead of manually creating a scatter plot for every combination of columns, a pair plot generates them all in one call - making it one of the fastest ways to spot correlated variables, clusters, and potential outliers before deeper analysis.

Pair plots become cluttered and slow with a large number of columns - it's common practice to first narrow down to the most relevant numeric features before generating one.

Building a Pair Plot Step by Step

A pair plot is only as useful as the data you feed it. Before calling the function, spend a minute preparing the DataFrame so the grid stays readable.

  1. Load the data and check column types with df.info(). Pair plots only draw numeric columns; text columns are ignored unless you pass them as hue.
  2. Handle missing values. Rows with gaps are dropped pair by pair, which can make some cells look emptier than others.
  3. Pick the columns you care about with the vars argument instead of plotting everything.
  4. Choose a hue column if you want to see whether groups separate.
  5. Read the grid cell by cell, starting with the diagonal.
import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset("penguins").dropna()

g = sns.pairplot(
    df,
    vars=["bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g"],
    hue="species",
    diag_kind="kde",      # smooth density curves on the diagonal
    corner=True,          # hide the duplicate upper triangle
    plot_kws={"alpha": 0.6, "s": 25}
)
g.fig.suptitle("Penguin measurements by species", y=1.02)
plt.show()

Reading the Grid Like an Analyst

In the penguin example, the diagonal curves show each measurement's spread per species. If one species has a density curve sitting far away from the others, that single feature already separates it well.

In the scatter cells, look for three things. A tight upward or downward band means two features are strongly correlated, so a model may not need both. Distinct coloured blobs mean the groups are separable, which is good news for classification. Isolated dots far from every cluster are candidates for outlier checks.

Setting corner=True is worth remembering: the upper and lower triangles show the same pairs with axes swapped, so hiding one half removes clutter without losing information.

Pair Plot or Something Else?

GoalBetter choice
Quick look at 3 to 6 numeric featuresPair plot
Correlation strength across 20+ columnsCorrelation heatmap
One relationship in detailsns.jointplot or a single scatter plot
Very large datasetPair plot on a random sample, or hexbin plots

For datasets with many rows, sample first with df.sample(2000, random_state=1). The shapes stay the same, and rendering becomes far quicker.

Common Mistakes and a Quick Checklist

  • Plotting ID columns or row numbers, which creates meaningless diagonal stripes.
  • Using a hue column with dozens of categories, which turns the legend into noise.
  • Comparing features on wildly different scales and assuming flat clouds mean no relationship.
  • Treating visual correlation as proof of cause.

Checklist: limit columns with vars, drop or fill missing values, add a meaningful hue, use corner=True, sample large data, then confirm any pattern with a correlation number.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course