Skip to content
svgseasonal-subseries

Seasonal subseries (cycle plot)

What is the seasonal pattern, and is each month changing across years?

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

How to read it

  1. Each mini line is one month across the years.
  2. Compare the horizontal segments, the monthly means: they show the seasonal shape.
  3. Compare the slopes: a steeper month is changing faster across years.
  1. Callout 1: One month's values, year by year.
  2. Callout 2: The segment: this month's mean. Peaks here show the season.

Watch out

  • With only a few years, a month's mean rests on a few values.

Defaults

Year points
On
Mark each year's value on the mini lines.

Pinned in the code

  • Rows are averaged per UTC calendar month; each month's panel plots those monthly means in year order.
  • The horizontal segment is the mean of the plotted monthly means (R `monthplot`, `feasts::gg_subseries`).
  • Rising mini-lines within a month show trend; differences between segments show seasonality.
  • All calendar arithmetic is in UTC; timestamps are epoch milliseconds.
# Seasonal subseries (cycle plot) — Codesplash Chart Lab (recipe "seasonal-subseries")
# controls: points=true
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("seasonal-subseries-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"])

X, Y = "month", "passengers_k"
d = df.dropna(subset=[X, Y])
monthly = d.groupby(d[X].dt.to_period("M"))[Y].mean()  # mean per UTC calendar month
sub = pd.DataFrame({"year": monthly.index.year, "month": monthly.index.month, "value": monthly.to_numpy()})
month_mean = sub.groupby("month")["value"].mean()  # the horizontal segment: mean of the monthly means
MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

fig, ax = plt.subplots(figsize=(9, 4))
for m in range(1, 13):
    pts = sub[sub["month"] == m].sort_values("year")
    if pts.empty:
        continue
    xs = m + np.linspace(-0.35, 0.35, len(pts)) if len(pts) > 1 else np.array([m])  # years in order within the month
    ax.plot(xs, pts["value"], color=PALETTE[0], linewidth=1.3, marker="o", markersize=3)
    ax.hlines(month_mean[m], m - 0.38, m + 0.38, color=PALETTE[1], linewidth=2)
ax.set_xticks(range(1, 13), MONTHS)
ax.set_ylabel("passengers_k" + " (monthly mean)")
plt.show()

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