Skip to content
svgcircular-dot

Circular dot plot

Where does each individual angle fall, and how do groups compare?

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

How to read it

  1. Read each dot as one angle, stacked outward from its ring.
  2. Each ring is one group.
  3. Read inner arrows as group mean directions.
  1. Callout 1: A group's dots: clustered around this direction.
  2. Callout 2: Mean direction arrow.
  3. Callout 3: A ring per group.

Watch out

  • Don't compute a usual mean on angles: the mean of 350° and 10° is 0°, not 180°.

Defaults

Angles are in
Degrees
How the column measures direction; the dial is labelled to match.
Also: Radians · Hours of the day · 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)
Stacking resolution (sectors)
72
How finely angles are binned before stacking.
Range 12 to 360, step 6

Pinned in the code

  • Each angle is placed at the centre of its sector (resolution 360/k) and stacked outward; nothing is smoothed.
  • One ring per group, inner to outer in level order; inner arrows: mean direction and R̄ per group (scaled to the inner disc).
# Circular dot plot — Codesplash Chart Lab (recipe "circular-dot")
# controls: units=degrees, orientation=compass, bins=72
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"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["-", (0, (6, 3)), (0, (1.5, 2.5)), (0, (8, 3, 2, 3)), (0, (12, 4)), (0, (3, 3)), (0, (8, 2, 2, 2, 2, 2)), (0, (1.5, 5))]
SERIES_MARKERS = ["o", "s", "^", "D", "P", "*", "2", "v"]

df = pd.read_csv("circular-dot-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["group"] = pd.Categorical(df["group"].astype("string"), categories=["control", "magnet", "anosmic"])

_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 = "degrees", True  # compass: 0 at the top, clockwise; else 0 at the right, counter-clockwise
PERIOD, ORIGIN = 360, 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 = ["0°", "45°", "90°", "135°", "180°", "225°", "270°", "315°"]
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)
def circ_stats(t):
    C, S = np.cos(2 * np.pi * t).sum(), np.sin(2 * np.pi * t).sum()
    n = len(t)
    return (np.arctan2(S, C) / (2 * np.pi)) % 1, (np.hypot(C, S) / n if n else np.nan)
def grouped_turns(df, A, G, k):
    d = df.dropna(subset=[A])
    if not G:
        return [("", to_turn(d[A]))]
    return [(g, to_turn(d.loc[d[G].astype(str) == g, A])) for g in freq_levels(d[G], k)]
A = "bearing"
G = "group"
BINS = 72  # stacking resolution (sectors)
groups = grouped_turns(df, A, G, 6)
gap = 0.55 / len(groups)  # one ring per group, inner to outer
stacked = []
for i, (name, t) in enumerate(groups):
    b = np.minimum(BINS - 1, np.floor(t * BINS).astype(int))
    level = pd.Series(b).groupby(b).cumcount().to_numpy()  # dots stack outward in their sector
    stacked.append(((b + 0.5) / BINS, level))
max_level = max([lv.max() + 1 for _, lv in stacked if len(lv)] or [1])
step = min(0.024, gap * 0.9 / max_level, 2 * np.pi * 0.45 / BINS)
fig, ax = plt.subplots(figsize=(6.4, 6.4), subplot_kw={"projection": "polar"})
dial(ax)
ring = np.linspace(0, 2 * np.pi, 361)
for i, ((name, t), (tc, level)) in enumerate(zip(groups, stacked)):
    base = 0.4 + i * gap
    col = PALETTE[i % len(PALETTE)] if G else REF
    ax.plot(ring, np.full_like(ring, base), color=GREY, linewidth=0.8)
    ax.scatter(2 * np.pi * tc, base + 0.42 * step + level * step, s=12, color=col, marker=SERIES_MARKERS[i % 8] if G else "o", label=name or None, zorder=3)  # shape per group, as in the app
    mu, rbar = circ_stats(t)  # inner arrows: mean direction and R̄, scaled to the inner disc
    ax.annotate("", xy=(2 * np.pi * mu, 0.36 * rbar), xytext=(0, 0), arrowprops=dict(arrowstyle="-|>", color=col, lw=1.6, linestyle=SERIES_DASHES[i % 8] if G else "-"))
ax.set_ylim(0, 1)
ax.set_yticks([])
if G:
    ax.legend(fontsize=8, loc="upper right", bbox_to_anchor=(1.18, 1.1))
plt.show()

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