Skip to content
svgradial-heatmap

Radial heatmap

How does activity vary round the clock (or the year), for each day, store or segment?

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

How to read it

  1. Read rings as categories and sectors as times.
  2. Find the dark sectors: when each category peaks.
  3. Compare between rings for different rhythms.
  1. Callout 1: A dark sector: a busy time.
  2. Callout 2: Ring labels: categories.
  3. Callout 3: Time starts at the top.

Watch out

  • Outer rings look larger for the same sector. Compare colour, not area.

Defaults

Angles are in
Hours of the day
How the column measures direction; the dial is labelled to match.
Also: Degrees · Radians · Weekday (1 = Mon) · Month (1–12) · Day of year
Zero and direction
Top, clockwise (compass, clock)
Compass bearings and clock times start at the top and run clockwise; mathematical angles start at the right.
Also: Right, counter-clockwise (maths)
Sectors
24
How many sectors divide the circle.
Range 4 to 96, step 1
Cell value
Count of rows
What each cell's colour shows, such as a count, a sum or a mean.
Also: Sum of value · Mean of value

Pinned in the code

  • Sector i covers [i/k, (i + 1)/k) of the cycle from angle 0; rings run inner to outer in level order.
  • Sequential colour from the lowest to the highest cell (count, sum or mean); empty cells are drawn dim.

Use with care

Outer rings are larger than inner ones; read colour, not area.

# Radial heatmap — Codesplash Chart Lab (recipe "radial-heatmap")
# controls: units=hours, orientation=compass, bins=24, stat=count
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap

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("radial-heatmap-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["weekday"] = pd.Categorical(df["weekday"].astype("string"), categories=["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"])

_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")
def freq_levels(s, k=8):
    """Declared level order when the column is categorical, else by descending count (ties A→Z)."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [str(v) for v in s.cat.categories][:k]
    vc = s.dropna().astype(str).value_counts()
    return sorted(vc.index, key=lambda v: (-vc[v], v))[:k]
UNITS, COMPASS = "hours", True  # compass: 0 at the top, clockwise; else 0 at the right, counter-clockwise
PERIOD, ORIGIN = 24, 0  # one full turn, and the value at angle 0
TICK_T = [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875]
TICK_LABELS = ["00:00", "03:00", "06:00", "09:00", "12:00", "15:00", "18:00", "21:00"]
def to_turn(v):
    return np.mod((np.asarray(v, dtype=float) - ORIGIN) / PERIOD, 1.0)
def dial(ax):
    ax.set_theta_zero_location("N" if COMPASS else "E")
    ax.set_theta_direction(-1 if COMPASS else 1)
    ax.set_xticks([2 * np.pi * t for t in TICK_T], TICK_LABELS)
    ax.grid(True, linewidth=0.5, alpha=0.6)
A = "hour"
RING = "weekday"
V = "spend"
BINS, STAT = 24, "count"  # cell value: count, sum or mean
d = df.dropna(subset=[A] + ([V] if V else []))
rings = freq_levels(d[RING], 12) if RING else ["all"]  # inner to outer
ri = d[RING].astype(str).map({r: i for i, r in enumerate(rings)}) if RING else pd.Series(0, index=d.index)
d, ri = d[ri.notna()], ri[ri.notna()].astype(int).to_numpy()
b = np.minimum(BINS - 1, np.floor(to_turn(d[A]) * BINS).astype(int))
x = d[V].to_numpy(float) if V else np.ones(len(d))
total, count = np.zeros((len(rings), BINS)), np.zeros((len(rings), BINS))
np.add.at(total, (ri, b), x)
np.add.at(count, (ri, b), 1)
with np.errstate(invalid="ignore", divide="ignore"):
    cell = count if STAT == "count" else total if STAT == "sum" else np.where(count > 0, total / count, np.nan)
finite = cell[np.isfinite(cell)]
lo, hi = min(finite.min(), 0), max(finite.max(), 1)
cmap = LinearSegmentedColormap.from_list("seq", SEQ)
INNER = 0.22
w = (1 - INNER) / len(rings)
fig, ax = plt.subplots(figsize=(6.8, 6.4), subplot_kw={"projection": "polar"})
dial(ax)
start = 2 * np.pi * np.arange(BINS) / BINS
for i in range(len(rings)):
    colours = [cmap((v - lo) / (hi - lo)) if np.isfinite(v) else GREY for v in cell[i]]
    ax.bar(start, w * 0.97, bottom=INNER + i * w, width=2 * np.pi / BINS, align="edge", color=colours, edgecolor="white", linewidth=0.3)
ax.set_ylim(0, 1)
ax.set_yticks([INNER + (i + 0.5) * w for i in range(len(rings))], rings if RING else [""], fontsize=7)
fig.colorbar(plt.cm.ScalarMappable(norm=plt.Normalize(lo, hi), cmap=cmap), ax=ax, shrink=0.7, pad=0.1, label=STAT if STAT == "count" or not V else f"{STAT} of {V}")
plt.show()

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