Skip to content
svgupset

UpSet of missing patterns

Which combinations of columns are missing together, and how often?

Demo data · seed 20261101 · 600 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read a dot column as a combination of columns missing together.
  2. Read the bar above it as how many rows have that exact combination.
  3. Read the small bars at the left for each column's total.
  1. Callout 1: Height: rows with exactly this pattern.
  2. Callout 2: Joined dots: the columns missing together.
  3. Callout 3: Bars at the left: total missing per column.

Watch out

  • Patterns beyond the top few are collapsed; the note counts how many were left out.

Defaults

Patterns shown
12
How many missing-value patterns to show, most common first.
Range 3 to 30, step 1

Pinned in the code

  • Each incomplete row counts once, under the exact set of columns it is missing (exclusive intersections, as in naniar `gg_miss_upset`).
  • Patterns are ordered by row count (ties: fewer columns first); beyond the top k they are summarized in the footer.
  • Set sizes on the left are the total missing count per column; complete rows are reported, not drawn.
  • Bars for single-column patterns use the first palette colour, multi-column patterns the fifth.
# UpSet of missing patterns — Codesplash Chart Lab (recipe "upset")
# controls: top=12
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("upset-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["last_purchase"] = pd.to_datetime(df["last_purchase"])
df["region"] = pd.Categorical(df["region"].astype("string"), categories=["North", "South", "East", "West"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
COLS = ["age", "region", "income", "last_purchase", "satisfaction", "nps", "comments"]
miss = df[COLS].isna()  # missing = NULL or not-a-number
size = miss.sum()
used = sorted([c for c in COLS if size[c] > 0], key=lambda c: (-size[c], COLS.index(c)))  # sets by missing count
key = miss[used].astype(int).astype(str).agg("".join, axis=1)
complete = int((~miss[used].any(axis=1)).sum())
counts = key[key.str.contains("1")].value_counts()  # each incomplete row once, under its exact set
# order: row count, then fewer columns, then the key descending (the app's tie-break)
patterns = sorted(counts.items(), key=lambda kv: (-kv[1], kv[0].count("1"), tuple(-int(ch) for ch in kv[0])))
top, rest = patterns[:12], patterns[12:]

fig = plt.figure(figsize=(9, 5))
gs = fig.add_gridspec(2, 2, width_ratios=(1, 4), height_ratios=(2, 1.3), hspace=0.05, wspace=0.45)  # room for the set names
bars, matrix, sets = fig.add_subplot(gs[0, 1]), fig.add_subplot(gs[1, 1]), fig.add_subplot(gs[1, 0])
xs = np.arange(len(top))
colours = [PALETTE[0] if k.count("1") == 1 else PALETTE[4] for k, _ in top]  # single-column vs multi-column patterns
bars.bar(xs, [n for _, n in top], color=colours)
bars.bar_label(bars.containers[0], fontsize=7)
bars.set_xticks([])
bars.set_ylabel("rows")
bars.set_title(f"{complete:,} complete rows" + (f" · {len(rest)} more patterns ({sum(n for _, n in rest):,} rows)" if rest else ""), fontsize=9, loc="left")
for j, (k, _) in enumerate(top):
    on = [i for i, ch in enumerate(k) if ch == "1"]
    matrix.scatter([j] * len(used), range(len(used)), s=40, color=GREY, zorder=2)
    matrix.scatter([j] * len(on), on, s=40, color=REF, zorder=3)
    if len(on) > 1:
        matrix.plot([j, j], [min(on), max(on)], color=REF, linewidth=1.5, zorder=2)
matrix.set_yticks(range(len(used)), used, fontsize=8)
matrix.set_xticks([])
matrix.set_xlim(bars.get_xlim())
matrix.invert_yaxis()
matrix.grid(False)
sets.barh(range(len(used)), [size[c] for c in used], color=REF)
sets.set_ylim(matrix.get_ylim())
sets.invert_xaxis()
sets.set_yticks([])
sets.set_xlabel("missing", fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads upset-demo.csv · app theme from the optional codesplash helper