svgcircular-ecdf
Circular ECDF vs uniform
How far are the angles from being spread evenly round the circle?
How to read it
- Read the curve as the cumulative share going round from 0.
- A diagonal line means an even spread round the circle.
- Read the largest gaps as Kuiper's statistic.
- Callout 1: The largest gap from uniform.
- Callout 2: The uniform diagonal.
Watch out
- The starting point is arbitrary; that's why Kuiper's test uses both gaps.
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
Pinned in the code
- x = position round the circle from angle 0; y = share of angles at or before it; the dashed diagonal is a uniform circle.
- Kuiper's V = D⁺ + D⁻ (largest gaps above and below the diagonal) does not depend on where the circle is cut; Stephens' V* = V(√n + 0.155 + 0.24/√n).
Use with care
The curve itself depends on the starting point 0; only D⁺ + D⁻ is rotation invariant.
# Circular ECDF vs uniform — Codesplash Chart Lab (recipe "circular-ecdf")
# controls: units=hours
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("circular-ecdf-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_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")
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 kuiper(t):
u = np.sort(t)
n = len(u)
F = np.arange(1, n + 1) / n
plus, minus = F - u, u - (F - 1 / n)
ip, im = int(np.argmax(plus)), int(np.argmax(minus)) # first largest gaps, as the app
return u, F, max(plus[ip], 0), u[ip], max(minus[im], 0), u[im], ip, im
A = "hour"
t = to_turn(df[A].dropna())
u, F, d_plus, at_plus, d_minus, at_minus, ip, im = kuiper(t)
n = len(u)
vstar = (d_plus + d_minus) * (np.sqrt(n) + 0.155 + 0.24 / np.sqrt(n)) # Kuiper's modified V*
fig, ax = plt.subplots(figsize=(7, 5))
ax.plot([0, 1], [0, 1], color=REF, linestyle="--", linewidth=1, label="uniform")
ax.step(np.concatenate([[0], u, [1]]), np.concatenate([[0], F, [1]]), where="post", color=PALETTE[0], linewidth=2, label=A)
ax.plot([at_plus, at_plus], [at_plus, F[ip]], color=PALETTE[3], linewidth=2.5, label=f"Kuiper D+ and D- (V* = {vstar:.2f})")
ax.plot([at_minus, at_minus], [F[im] - 1 / n, at_minus], color=PALETTE[3], linewidth=2.5)
ax.set_xticks(TICK_T, TICK_LABELS)
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_xlabel(A)
ax.set_ylabel("cumulative share")
ax.legend(fontsize=8, loc="upper left")
plt.show()Needs pandas, numpy, matplotlib · reads circular-ecdf-demo.csv · app theme from the optional codesplash helper
# Circular ECDF vs uniform — Codesplash Chart Lab (recipe "circular-ecdf")
# controls: units=hours
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
df = pd.read_csv("circular-ecdf-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_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")
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 kuiper(t):
u = np.sort(t)
n = len(u)
F = np.arange(1, n + 1) / n
plus, minus = F - u, u - (F - 1 / n)
ip, im = int(np.argmax(plus)), int(np.argmax(minus)) # first largest gaps, as the app
return u, F, max(plus[ip], 0), u[ip], max(minus[im], 0), u[im], ip, im
A = "hour"
t = to_turn(df[A].dropna())
u, F, d_plus, at_plus, d_minus, at_minus, ip, im = kuiper(t)
n = len(u)
vstar = (d_plus + d_minus) * (np.sqrt(n) + 0.155 + 0.24 / np.sqrt(n))
fig = go.Figure()
fig.add_scatter(x=[0, 1], y=[0, 1], mode="lines", line=dict(color=REF, dash="dash", width=1), name="uniform")
fig.add_scatter(x=np.concatenate([[0], u, [1]]), y=np.concatenate([[0], F, [1]]), mode="lines", line=dict(color=PALETTE[0], width=2, shape="hv"), name=A)
fig.add_scatter(x=[at_plus, at_plus, None, at_minus, at_minus], y=[at_plus, F[ip], None, F[im] - 1 / n, at_minus], mode="lines",
line=dict(color=PALETTE[3], width=3), name=f"Kuiper D+ and D- (V* = {vstar:.2f})")
fig.update_xaxes(range=[0, 1], tickvals=TICK_T, ticktext=TICK_LABELS, title=A)
fig.update_yaxes(range=[0, 1], title="cumulative share")
fig.show()Needs pandas, numpy, plotly · reads circular-ecdf-demo.csv · app theme from the optional codesplash helper
# Circular ECDF vs uniform — Codesplash Chart Lab (recipe "circular-ecdf")
# controls: units=hours
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("circular-ecdf-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
compass <- TRUE # compass: 0 at the top, clockwise; else 0 at the right, counter-clockwise
period <- 24; origin <- 0 # one full turn, and the value at angle 0 (hours)
tick_t <- c(0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875)
tick_labels <- c("00:00", "03:00", "06:00", "09:00", "12:00", "15:00", "18:00", "21:00")
to_turn <- function(v) ((v - origin) / period) %% 1
a_col <- "hour"
u <- sort(to_turn(df[[a_col]][!is.na(df[[a_col]])])); n <- length(u)
f <- seq_len(n) / n
ip <- which.max(f - u); im <- which.max(u - (f - 1 / n)) # Kuiper's largest gaps D+ and D-
vstar <- (max(f - u, 0) + max(u - (f - 1 / n), 0)) * (sqrt(n) + 0.155 + 0.24 / sqrt(n))
steps <- data.frame(x = c(0, u, 1), y = c(0, f, 1))
gaps <- data.frame(x = c(u[ip], u[im]), y = c(u[ip], f[im] - 1 / n), yend = c(f[ip], u[im]))
p <- ggplot(steps, aes(x, y)) + geom_abline(slope = 1, intercept = 0, linetype = "dashed", colour = ref_col) +
geom_step(colour = cs_cat[1], linewidth = 0.9) +
geom_segment(data = gaps, aes(xend = x, yend = yend), colour = cs_cat[4], linewidth = 1.3) +
annotate("text", x = 0.02, y = 0.97, hjust = 0, size = 3.2, label = sprintf("Kuiper D+ and D- (V* = %.2f)", vstar)) +
scale_x_continuous(limits = c(0, 1), breaks = tick_t, labels = tick_labels) + coord_cartesian(ylim = c(0, 1)) +
labs(x = a_col, y = "cumulative share") + theme_cs
print(p)Needs ggplot2 · reads circular-ecdf-demo.csv · app theme from the optional codesplashr helper