Skip to content
svgseries-line

Series with break marker

How does the series move over time, and where is an estimated break?

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

How to read it

  1. Read the level and any drift in the series.
  2. Look for a marked break after an estimated date.
  3. Compare the level before and after that mark.
  1. Callout 1: The level shifts around here.
  2. Callout 2: After the shift, the series varies around a higher level.

Watch out

  • A break found by searching all dates isn't an independent test of that date.

Defaults

Break after observation (0 = none)
0
1-based position in time order of the last observation before the break.
Range 0 to 100,000, step 1
Show points
Off
Mark the individual observations on the line.

Pinned in the code

  • Rows are sorted by the time column (row order when absent); missing values break the line.
  • Time may be dates or numbers (years, hours, positions): the axis follows the column's kind.
  • The break marker sits on the last observation before the break, as Zivot–Andrews reports it.
# Series with break marker — Codesplash Chart Lab (recipe "series-line")
# controls: marker=0, points=false
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("series-line-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["month"] = pd.to_datetime(df["month"])

_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 levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
def ordered(d, x, cols):
    """Rows with the needed values, sorted by the time column (stable); row order when there is none."""
    d = d.dropna(subset=[c for c in cols if c] + ([x] if x else []))
    return d.sort_values(x, kind="stable") if x else d

def time_of(d, x):
    return d[x] if x else pd.Series(np.arange(1, len(d) + 1), index=d.index)
X = "month"
Y = "index"
G = None
MARKER, POINTS = 0, False  # break after this position (0 = none)
d = ordered(df, X, [Y, G])
groups = levels_of(d[G]) if G else [None]
fig, ax = plt.subplots(figsize=(8, 4))
for i, g in enumerate(groups):
    s = d if g is None else d[d[G].astype(str) == str(g)]
    ax.plot(time_of(s, X), s[Y], color=PALETTE[i % len(PALETTE)], linewidth=1.6, label=None if g is None else str(g))
    if POINTS and i == 0:
        ax.scatter(time_of(s, X), s[Y], s=6, color=PALETTE[0])
first = d if G is None else d[d[G].astype(str) == str(groups[0])]
if 0 < MARKER <= len(first):
    ax.axvline(time_of(first, X).iloc[MARKER - 1], color=REF, linestyle="--", linewidth=1.2, label="estimated break")
ax.set_xlabel("month")
ax.set_ylabel(Y)
if G or MARKER:
    ax.legend(frameon=False)
plt.show()

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