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
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":
sc = ax.scatter(gdp, life_exp, s=population/1e6, c=continent_codes, cmap="tab10")fig.colorbar(sc, label="continent")
Key takeaways
- 01ax.scatter draws one dot per observation — for relationships between two variables.
- 02Encode extra dimensions with s (size) and c (colour) — a bubble chart.
- 03Use alpha < 1 to reveal density where points overlap.
- 04For massive datasets, prefer hexbin over an overplotted scatter.
