Single logo
  • Courses
  • Blog
  • About
Join for freeJoin free
Learning pathExplore a Dataset Before You Model
  1. 1
    First Look at a Dataset: 6 Checks Before You Plot or Model
  2. 2
    Plotting Distributions with seaborn: Histograms, KDE, Counts and log1p
  3. 3
    Scatter Plots and Pair Plots: See How Two Columns Relate
  4. 4
    Finding Outliers: Box Plots, Violin Plots and the IQR Rule
  5. 5
    Correlation and Heatmaps: Covariance, df.corr() and What They Miss
  6. 6
    Train-Test Split and Data Leakage: Split First, Learn After
  1. Blog
  2. /
  3. Machine Learning
  4. /
  5. Exploratory Data Analysis

Learning path: Explore a Dataset Before You Model · Step 3 of 6

Scatter Plots and Pair Plots: See How Two Columns Relate

Draw one dot per row with seaborn scatterplot, colour the dots by group with hue, turn a clean split into a one-line rule, and read every pair at once with pairplot. Shown on iris and tips.

Chaand Sheikh

·27 November 2026Exploratory Data Analysis

What you will learn

  • Draw a scatter plot with sns.scatterplot and colour it by group with hue
  • Turn a split you see in a plot into a rule and check it with pandas
  • Read a pair plot: the diagonal, the lower half and the upper half
  • Explain why pair plots stop being useful on wide data

Before you start

  • Reading a CSV with pandas
  • Plotting Distributions with seaborn

Think of speed dating for columns. Every pair of columns sits down together for a few minutes, and you see which pairs click. In the iris flowers, petal length and petal width follow a clear pattern. Sepal length and sepal width? Just a cloud.

A scatter plot is that date: two columns, one dot for every row. In this lesson you'll draw scatter plots, colour them by group with hue, turn what you see into a rule, and draw every pair at once with a pair plot.

Last time we looked at one column at a time in Plotting Distributions with seaborn. Now it's two.

Load the data

import math
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

iris = pd.read_csv("iris.csv")
tips = pd.read_csv("tips.csv")

Two columns, one dot per row

sns.scatterplot(data=iris, x="sepal_length",
                y="sepal_width")
plt.show()

Here's how the plot is built. Take the first flower: sepal length 5.1, sepal width 3.5. Go 5.1 across and 3.5 up, and that's the first dot. Every row does the same, so 150 flowers give 150 dots.

The result is a cloud. It's hard to say anything useful from it.

hue colours the dots by group

What's missing is the species. Add one argument:

sns.scatterplot(data=iris, x="sepal_length",
                y="sepal_width", hue="species")
plt.show()
Scatter plot of iris sepal_length against sepal_width, coloured by species. Blue setosa dots sit top left with short, wide sepals. Orange versicolor and green virginica dots are mixed together to the right.
Sepal length vs sepal width, coloured by species: setosa has its own corner, the other two mix.

Each species gets its own colour, and the picture changes. Setosa sits in its own corner, with short but wide sepals. Versicolor and virginica are still mixed together. So these two columns alone can't separate everything.

Petals separate the species

Try the petal columns instead, with a dashed vertical line at 2.5:

sns.scatterplot(data=iris, x="petal_length",
                y="petal_width", hue="species")
plt.axvline(2.5, linestyle="--", color="black")
plt.show()
Scatter plot of iris petal_length against petal_width, coloured by species, with a dashed vertical line at petal length 2.5. All blue setosa dots are left of the line near the bottom; orange versicolor and green virginica dots form a rising band to the right.
Petal length vs petal width: every setosa is left of the dashed line at 2.5.

Three tidy groups. Everything left of the line is setosa, and nothing else is there. One straight line separates one whole species.

Test the line in code

A picture can fool you, so check it. rule is True for every flower left of the line. The tilde ~ flips it, so the second print counts the other side.

rule = iris["petal_length"] < 2.5
print(iris[rule]["species"].value_counts())
print(iris[~rule]["species"].value_counts())
species
setosa    50
Name: count, dtype: int64
species
versicolor    50
virginica     50
Name: count, dtype: int64

Left of the line: all 50 setosa and nothing else. Right of the line: 50 versicolor, 50 virginica, no setosa at all. That's a hand-written model, the simplest model there is, and the scatter plot gave it to us.

Two numbers moving together

Scatter plots also show how two numbers move together. Here are the 244 restaurant bills, total bill across and tip up:

sns.scatterplot(data=tips, x="total_bill", y="tip")
plt.show()

As the bill grows, the tip tends to grow too. That's a positive relationship. But the dots spread out: bills between 20 and 25 dollars get tips anywhere from about 2 up to 6.5. So it's a trend, not a rule. You'll put a number on trends like this in Correlation and Heatmaps.

Every pair at once: the pair plot

Checking every pair by hand is slow. pairplot draws them all in one grid.

sns.pairplot(iris, hue="species")
plt.show()
Four by four seaborn pair plot of the iris columns sepal_length, sepal_width, petal_length and petal_width, coloured by species. The diagonal shows one density curve per species for each column; the other cells are scatter plots of each pair, with the upper half mirroring the lower half.
The iris pair plot: density curves on the diagonal, one scatter plot per pair everywhere else.

Iris has four number columns, so you get a four by four grid. The four measurements label both the rows and the columns of the grid. Here's how to read it:

  • The diagonal: a column meets itself, so each cell shows that one column on its own. With hue, that's one smooth curve per species.
  • Below the diagonal: one scatter plot for each pair of columns.
  • Above the diagonal: the same pairs again, with the axes flipped. You only need to read one half.

Four columns, six pairs. Petal length against petal width again separates setosa very clearly.

Why pair plots don't scale

The number of pairs from n columns is "n choose 2". math.comb counts it:

for n in [4, 24, 100]:
    print(n, "columns ->", math.comb(n, 2), "pairs")
4 columns -> 6 pairs
24 columns -> 276 pairs
100 columns -> 4950 pairs

Six pairs are easy to read. The Rain in Australia weather data has 24 columns, which means 276 pairs. A hundred columns give 4,950. Nobody can read that, so for wide data you need a summary, such as a correlation heatmap, instead of thousands of little pictures.

Common mistakes

  • Stopping at the cloud. A plain scatter plot can hide groups. Try hue with the label.
  • Trusting the picture alone. Turn a split you see into a rule and count it, like the < 2.5 check above.
  • Reading a trend as a rule. Tips grow with the bill, but the spread is wide.
  • Pair-plotting wide data. Fine for 4 columns, useless for 24 or more.

Quick recap

IdeaCodeWhat we saw
Scatter plotsns.scatterplot(x=..., y=...)150 dots for 150 flowers
Colour by grouphue="species"Setosa sits in its own corner
Split becomes a rulepetal_length < 2.550 setosa on one side, 100 others on the other
Positive trendtip vs total_billTips grow with the bill, with a wide spread
Every pairsns.pairplot(iris, hue="species")4 columns, 6 pairs
Pairs grow fastmath.comb(n, 2)24 columns: 276 pairs

Try it yourself

Draw a scatter plot of tip against total_bill with hue="smoker". Do both groups follow the same trend?

The notebook and both datasets are in the StudyEasy AI Community, free to join.

Built this? Share your solution in the StudyEasy AI Community.

Join free on Skool →
← Previous
Plotting Distributions with seaborn: Histograms, KDE, Counts and log1p
Next →
Finding Outliers: Box Plots, Violin Plots and the IQR Rule
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Related articles
First Look at a Dataset: 6 Checks Before You Plot or Model

Six quick pandas checks that tell you what's inside a dataset: size, types, gaps, spread, label balance and duplicates. Shown on 142,193 days of Australian weather.

Plotting Distributions with seaborn: Histograms, KDE, Counts and log1p

Look at one column at a time: read the peak and the tail of a histogram, compare groups with hue, count categories, and tame a long tail with log1p. Shown on restaurant bills and iris flowers.

Finding Outliers: Box Plots, Violin Plots and the IQR Rule

Read a box plot from its five numbers, flag outliers with the 1.5 x IQR rule in pandas, compare groups with box and violin plots, and cap extreme values with clip. Shown on 244 restaurant bills.

Correlation and Heatmaps: Covariance, df.corr() and What They Miss

Put one number on "these two columns move together": why covariance depends on units, how correlation fixes it, scanning every pair with df.corr() and a seaborn heatmap, and the two traps correlation can't see.

On this page
  • Load the data
  • Two columns, one dot per row
  • hue colours the dots by group
  • Petals separate the species
  • Test the line in code
  • Two numbers moving together
  • Every pair at once: the pair plot
  • Why pair plots don't scale
  • Common mistakes
  • Quick recap
  • Try it yourself
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool
Go deeper with a course

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.