Skip to content
svgconsensus-heatmap

Consensus matrix

How often do two rows end up in the same cluster when the data is resampled?

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

How to read it

  1. Read a cell as how often two rows cluster together across resamples.
  2. Solid dark blocks: stable clusters.
  3. Mottled cells between blocks: rows that move between clusters.
  1. Callout 1: A solid block: a stable cluster.
  2. Callout 2: Another block.
  3. Callout 3: Pale: these rows rarely cluster together.

Watch out

  • Stable doesn't mean real: an artefact of scaling can be perfectly stable.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the host's cs-ml evaluation or the Python/R engine); the chart computes nothing statistical.
  • Each cell is (resamples with both rows clustered together) / (resamples containing both rows); rows are a fixed evenly spaced sample, grouped by their cluster on the full data.
  • PAC (share of pairs strictly between 0.1 and 0.9) summarises ambiguity: lower is crisper.
# Consensus matrix — Codesplash Chart Lab (recipe "consensus-heatmap")
# controls: defaults
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("consensus-heatmap-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

R = "row (by cluster)"
C = "column (by cluster)"
V = "share of resamples together"
m = df.pivot_table(index=R, columns=C, values=V, aggfunc="mean").sort_index().sort_index(axis=1)
fig, ax = plt.subplots(figsize=(6, 5))
im = ax.imshow(m.to_numpy(), cmap="Blues", aspect="equal", interpolation="nearest", extent=[m.columns.min() - 0.5, m.columns.max() + 0.5, m.index.max() + 0.5, m.index.min() - 0.5])
fig.colorbar(im, label=V, shrink=0.8)
ax.set_xlabel("row (by cluster)")
ax.set_ylabel("row (by cluster)")
plt.show()

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