Skip to lesson content
navan✳THE BUILD LABPYTHON 3
0/101 complete
BUILD LAB / PYTHON/ Make the data visible
EXPERIMENT 52 / 101

Look for a relationship.

Compare paired measurements without pretending correlation is causation.

ADVANCED LAB
BY NAVAN SAMI◷ 11 MIN READPYTHON 3

01 The idea

A scatter plot shows observations as pairs of measurements. It helps reveal trends, clusters, and unusual points without connecting observations into an invented sequence. Marker transparency can help with overlap, but it does not solve every density problem. Treat an apparent relationship as a prompt for investigation, not automatic proof that one variable causes the other.

02 The experiment

Read it once. Predict what will happen. Then copy it into a .py file and run it in your local Python setup.

matplotlib_scatter.py
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
minutes = [10, 15, 22, 30, 38, 45]
issues = [1, 0, 2, 2, 4, 3]
fig, ax = plt.subplots(figsize=(6, 3.5), layout="constrained")
ax.scatter(minutes, issues, s=65, alpha=0.7, color="#ed5027", edgecolors="#71331e")
ax.set(xlabel="Review time (minutes)", ylabel="Issues found", title="A relationship worth investigating")
ax.grid(alpha=0.15)
fig.savefig("matplotlib-scatter.png", dpi=140, bbox_inches="tight")
plt.close(fig)
print("Saved matplotlib-scatter.png")
↳ EXPECTED OUTPUT
Saved matplotlib-scatter.png
Scatter plots & overplotting: chart generated by the Python example
THE OUTPUT, MADE VISIBLE · Generated from this lesson’s example.
Download chart ↗

03 Under the hood

  1. 1

    Each x value is paired with the y value at the same position. The sample is deliberately small and illustrative.

  2. 2

    s controls marker area, not diameter. If you encode another variable through size, explain its units and scale.

  3. 3

    A trend might reflect task complexity rather than a causal effect of review time. Investigate confounding variables and collect appropriate evidence before drawing conclusions.

04 Your turn, builder

A SMALL MISSION

Plot project effort against reported defects and annotate the point with the most defects.

Reveal one possible solution +
one_possible_solution.py
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
x, y = [12, 20, 35], [1, 4, 2]
fig, ax = plt.subplots(figsize=(6, 3.5), layout="constrained")
ax.scatter(x, y, color="#ed5027", s=70)
ax.annotate("Inspect this task", xy=(20, 4), xytext=(13, 4.5), arrowprops={"arrowstyle": "->"})
ax.set(xlabel="Effort (hours)", ylabel="Defects", ylim=(0, 5.5))
fig.savefig("challenge.png", dpi=140, bbox_inches="tight")
plt.close(fig)
print("Saved challenge.png")

05 Check your signal

QUICK SIGNAL CHECK

Does a visible scatter trend establish causation?

THAT’S ANOTHER IDEA IN YOUR TOOLKIT.

Experiment. Logged.

When you can explain the idea and make the example your own, mark it complete. Your log stays in this browser.

Keep exploring

Go deeper with the official Python guide ↗.

Built with curiosity. By Navan Sami. ↗Python 3 · Think. Try. Build.