Treat pairwise missingness, scales and the number of comparisons as part of the matrix.
Scatterplot matrices: disclose which rows support each pair
Each cell has its own population
A scatterplot matrix shows pairwise relationships among several variables. If missing values differ by column, the cell for queue depth versus delay may use different records from the cell for delay versus cost. A common complete-case filter makes populations consistent but may discard many rows. Pairwise deletion retains more data but changes the population from cell to cell. State which policy was used and print the valid count in every cell. Correlation heatmaps face the same coverage problem but hide the underlying point clouds.
Use one variable scale across its row and column
A variable appearing on several axes should keep a common unit and domain where possible. Otherwise the apparent slope and spread change as a reader moves across the grid. Label only the outer axes if the layout is tight, but keep units available in a companion table. Transformations such as logarithms must be consistent for every appearance of the variable, and invalid nonpositive values need an explicit exclusion count. Log-scale boundaries should be chosen for the data, not merely to make a diagonal cluster look tidy.
A matrix multiplies visual tests
With seven variables there are 21 distinct off-diagonal pairs. One remarkable-looking cell may occur by chance, especially after inspecting many matrices, filters and periods. Use the display to generate questions rather than to announce discovered laws. Annotate pre-specified comparisons, and follow up with a model or analysis suited to the decision. Regression overlays need their own fit population and assumptions; a line in every cell can overwhelm the matrix and invite unsupported causal readings.
Control density and reading order
Plotting the same large cohort in 42 mirrored cells can be expensive and visually opaque. Use the lower triangle for points and reserve the diagonal for univariate distributions or compact count summaries. Sample only with a declared rule, preserving rare groups if that is part of the question. Overplotting techniques can reveal concentration without creating false individual positions. Sort variables in a stable, meaningful sequence and offer a per-cell data table or drill-down so the matrix remains usable at phone width and high zoom.
Worked contract
from math import isfinite
def pairwise_points(records: list[dict[str, float | None]],
horizontal: str, vertical: str
) -> list[tuple[float, float]]:
if not horizontal or not vertical or horizontal == vertical:
raise ValueError("two distinct variable names required")
points = []
for record in records:
x_value, y_value = record.get(horizontal), record.get(vertical)
if x_value is None or y_value is None:
continue
if not isfinite(x_value) or not isfinite(y_value):
raise ValueError("non-finite values require an explicit policy")
points.append((x_value, y_value))
return points
depot_rows = [
{"queue": 47.0, "delay": 31.0, "cost": 81.0},
{"queue": 59.0, "delay": None, "cost": 97.0},
{"queue": 83.0, "delay": 43.0, "cost": None},
]
assert pairwise_points(depot_rows, "queue", "delay") == [(47, 31), (83, 43)]
assert pairwise_points(depot_rows, "queue", "cost") == [(47, 81), (59, 97)]Performance and operating cost
For P variables and N records, preparing every unique pair costs O(P squared times N) time. Retaining all displayed points for the lower triangle can take O(P squared times N) space; stream or aggregate when that footprint is too large. The example uses pairwise deletion and makes no correlation or significance claim. Report the per-cell count and dropped-row policy so two adjacent clouds are not mistaken for identical cohorts.
Common Mistakes
- Reporting one global sample size when cells use different valid rows.
- Auto-scaling the same variable differently across matrix cells.
- Treating the most striking of many inspected pairs as confirmed evidence.
- Rendering mirrored dense cells without a detail view or sampling record.
Validation drill
Build a lower-triangle matrix for seven operational measures. Put valid-row counts in all 21 cells, fix each variable's scale across appearances and identify three relationships chosen before viewing the grid.
