Skip to main content
Albero Academy

Scatter Plots

Show the relationship between two variables, point by point.

Core Plot Types8 min

A scatter plot draws one dot per observation, revealing the relationship between two numeric variables — correlation, clusters, outliers. Unlike a line, it makes no assumption of order.

ax.scatter

points, not lines
ax.scatter(x, y)
ax.scatter(x, y, s=sizes, c=values, cmap="viridis", alpha=0.6)
# s = per-point size, c = per-point colour value, alpha = transparency

Encoding more dimensions

Scatter plots can show up to four variables at once: x, y, point size (s) and colour (c) — a "bubble chart":

a bubble chart
sc = ax.scatter(gdp, life_exp, s=population/1e6, c=continent_codes, cmap="tab10")
fig.colorbar(sc, label="continent")

Key takeaways

  1. 01ax.scatter draws one dot per observation — for relationships between two variables.
  2. 02Encode extra dimensions with s (size) and c (colour) — a bubble chart.
  3. 03Use alpha < 1 to reveal density where points overlap.
  4. 04For massive datasets, prefer hexbin over an overplotted scatter.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.