svgchangepoint-timeline
Change-points on a timeline
When did this monitored metric shift, and which detectors noticed?
How to read it
- Read the line as one metric across monitor runs, oldest on the left.
- A dashed line marks a run where a detector signalled; its label says which one, or how many.
- Online detectors signal a little after a shift, so look at the runs just before a mark.
- Callout 1: A detector signalled at this run.
- Callout 2: The stable level before the shift.
Watch out
- A signal is a reason to look, not proof that something changed: stable series still false-alarm a few percent of the time.
- With fewer than 8 runs the detectors stay silent, which says nothing about whether the metric moved.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Draws the host's numbers as given; the chart computes nothing statistical.
- Online detectors (Page–Hinkley, CUSUM) mark the run at which they first noticed, a little after the shift; Pettitt marks the first run after its single shift; ADWIN marks the run at which it dropped older runs.
- A signal is a reason to look, not proof: over 50 stable runs Page–Hinkley and CUSUM still false-alarm a few percent of the time.
# Change-points on a timeline — Codesplash Chart Lab (recipe "changepoint-timeline")
# 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("changepoint-timeline-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["run"] = pd.to_datetime(df["run"])
T = "run"
V = "PSI of tenure"
M = "detectors"
d = df.dropna(subset=[T, V]).sort_values(T)
fig, ax = plt.subplots(figsize=(8, 4))
if M:
for _, row in d[d[M].fillna("").astype(str).str.len() > 0].iterrows():
ax.axvline(row[T], color="#c0392b", linestyle="--", linewidth=1)
ax.annotate(str(row[M]), (row[T], 1), xycoords=("data", "axes fraction"), xytext=(3, -10), textcoords="offset points", fontsize=8, color="#c0392b")
ax.plot(d[T], d[V], marker="o", markersize=3)
ax.set_xlabel(T)
ax.set_ylabel(V)
plt.show()Needs pandas, numpy, matplotlib · reads changepoint-timeline-demo.csv · app theme from the optional codesplash helper
# Change-points on a timeline — Codesplash Chart Lab (recipe "changepoint-timeline")
# controls: defaults
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("changepoint-timeline-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["run"] = pd.to_datetime(df["run"])
T = "run"
V = "PSI of tenure"
M = "detectors"
d = df.dropna(subset=[T, V]).sort_values(T)
fig = go.Figure(go.Scatter(x=d[T], y=d[V], mode="lines+markers", marker=dict(size=5), name=V))
if M:
for _, row in d[d[M].fillna("").astype(str).str.len() > 0].iterrows():
fig.add_shape(type="line", x0=row[T], x1=row[T], y0=0, y1=1, yref="paper", line=dict(color="#c0392b", dash="dash", width=1))
fig.add_annotation(x=row[T], y=1, yref="paper", text=str(row[M]), showarrow=False, font=dict(size=10, color="#c0392b"), xanchor="left")
fig.update_layout(xaxis_title=T, yaxis_title=V, template="plotly_white")
fig.show()Needs pandas, numpy, plotly · reads changepoint-timeline-demo.csv · app theme from the optional codesplash helper
# Change-points on a timeline — Codesplash Chart Lab (recipe "changepoint-timeline")
# controls: defaults
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("changepoint-timeline-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["run"]] <- as.POSIXct(df[["run"]], tz = "UTC")
df[["detectors"]] <- factor(df[["detectors"]])
T <- "run"
V <- "PSI of tenure"
M <- "detectors"
d <- df[!is.na(df[[T]]) & !is.na(df[[V]]), ]
d <- d[order(d[[T]]), ]
p <- ggplot(d, aes(x = .data[[T]], y = .data[[V]]))
if (!is.null(M)) {
hits <- d[!is.na(d[[M]]) & nzchar(as.character(d[[M]])), ]
p <- p + geom_vline(data = hits, aes(xintercept = .data[[T]]), colour = "#c0392b", linetype = "dashed") +
geom_text(data = hits, aes(x = .data[[T]], label = as.character(.data[[M]])), y = Inf, hjust = -0.05, vjust = 1.5, size = 3, colour = "#c0392b", inherit.aes = FALSE)
}
p <- p + geom_line() + geom_point(size = 1.2) + labs(x = T, y = V) + theme_minimal()
print(p)Needs ggplot2 · reads changepoint-timeline-demo.csv · app theme from the optional codesplashr helper