Use density cells and deliberate sampling when points overlap, while retaining the populations and exceptions that matter.
Dense scatterplots: reveal overlap without hiding rare observations
Overplotting changes what a point means
A scatterplot maps paired values to two position channels. When thousands of records land on the same pixels, the visible mark count no longer approximates the record count. Transparency can expose a dense center, but repeated strokes saturate and rare points can disappear beneath it. Before changing the mark style, count records per screen-space cell and inspect whether the question is about density, outliers, groups or exact cases. The chart question determines whether a point cloud is still the right view.
Bin at a declared resolution
A two-dimensional density grid counts observations inside fixed x and y intervals. It can show population structure without rendering every dot. The cells need axis units, bounds and bin width; changing cell size changes the picture. A cell count is not a probability unless divided by the declared population or area. Use the same grid for comparisons across cohorts, otherwise apparent hot spots may be a change in binning. Preserve a drill-down path to the original records where access rules permit it. A heatmap of density has the same color-domain obligations as any other heatmap.
Sampling is a data product
Uniform sampling can make a common cluster readable yet omit a rare but important failure mode. If the operational question concerns unusual refunds, retain those cases deliberately and label the sample design. A stratified sample can hold a fixed number from each category, but its plotted mix no longer reflects population proportions unless weights or counts are shown. Never present sampled points as the full dataset. Record the random seed, inclusion rule and population size. The sampling frame matters even when the result is only exploratory.
Separate trend from uncertainty
A diagonal cloud does not by itself establish a causal effect. Outliers, groups and repeated measures can alter the apparent slope. Show marginal distributions or group facets when one cluster masks another. If a fitted trend is added, distinguish raw marks from the fitted line and state whether the fit is weighted, filtered or calculated on the visible sample. Influence checks are needed before treating that line as a stable summary. A truncated axis can also make a weak relation seem strong.
Validate at the pixel budget
Test identical coordinates, boundary points, non-finite values and a small rare cohort. Count how many records end in each visible density cell, then reconcile the total with the filtered input. Hovering a cell should report its count and ranges, not invent a single representative record. At high density, compare a grid and a sampled-point layer side by side: the grid describes mass, while the points retain individual exceptions. On a small screen, favor one readable layer over simultaneous translucent layers that obscure both.
Worked contract
from math import floor, isfinite
def density_cells(points: list[tuple[float, float]],
x_bounds: tuple[float, float],
y_bounds: tuple[float, float],
columns: int, rows: int) -> dict[tuple[int, int], int]:
x_low, x_high = x_bounds
y_low, y_high = y_bounds
if columns < 1 or rows < 1 or x_low >= x_high or y_low >= y_high:
raise ValueError("invalid grid")
counts: dict[tuple[int, int], int] = {}
for amount, handling_minutes in points:
if not all(map(isfinite, (amount, handling_minutes))):
raise ValueError("non-finite observation")
if not (x_low <= amount <= x_high and
y_low <= handling_minutes <= y_high):
raise ValueError("point outside declared domain")
column = min(columns - 1, floor((amount - x_low) * columns / (x_high - x_low)))
row = min(rows - 1, floor((handling_minutes - y_low) * rows / (y_high - y_low)))
counts[(column, row)] = counts.get((column, row), 0) + 1
return counts
cells = density_cells([(47, 18), (47, 18), (81, 39)],
(0, 100), (0, 50), 5, 5)
assert sum(cells.values()) == 3 and max(cells.values()) == 2Performance and operating cost
For N points and C occupied cells, fixed-grid counting takes O(N) time and O(C) memory, with C no larger than the number of grid positions. Rendering one rectangle per occupied cell can be much cheaper than rendering N circles. The example rejects out-of-domain points; a production view may instead maintain an explicit overflow bucket, but it must label that choice. Recompute bins when the axis domain or pixel resolution changes, and do not confuse screen-density counts with a probability density estimate.
Common Mistakes
- Lowering opacity and assuming the visible marks still represent all records.
- Sampling rare cases away while evaluating an exception-handling workflow.
- Comparing density grids built with different bounds or cell widths.
- Calling a fitted slope causal based on a crowded scatterplot.
Validation drill
Generate 4,700 routine handling cases plus 31 rare high-delay cases. Compare raw points, a fixed grid and a seeded stratified sample; report whether each view keeps the rare cluster visible and whether displayed counts reconcile.
Read next
- Chart design starts with a question, unit and visual encoding
- Heatmaps: make missing cells, rates and color domains explicit
- Small multiples: compare groups with honest scales and facet order
- Regression diagnostics: residual pattern, scale and influential routes
Continue this visualization path
- Correlation heatmaps: show pairwise coverage before interpreting color
- Hexbin density: count overlapping points without hiding exposure
- Dual-axis charts: test whether two series really need one plot
- Beeswarm plots: show individual values without inventing spread
- Regression overlays: separate fitted trend from individual spread
- Regression residual plots: locate bias, spread and missing segments
- Lag plots: pair exact periods before reading dependence
- Embedding scatterplots: audit neighborhoods before naming clusters
- Bubble charts: scale the third measure by area
