Group repeated cycle positions, draw their chronological traces and calculate reference means only from complete cycles.
Seasonal subseries plots: compare the same cycle position across years
Choose a cycle for a real operational reason
A seasonal subseries plot groups observations by their position within a known repeating cycle: all first quarters together, all second quarters together and so on. Within each group, preserve chronological order across cycles and draw a reference mean or median for that position. The view exposes both differences between cycle positions and changes within one position over years. A quarterly series needs four positions; a weekly schedule might need seven weekdays. Do not infer the cycle merely because a pattern looks attractive after trying many candidates. Document the calendar origin and whether a period is a full business day, fiscal week or standard month. Autocorrelation plots can suggest repetition, but their lag peaks do not supply the business calendar. Time-series calendar rules fix the period definitions.
Align like positions and keep the trend visible
A quarter-one rise across years can coexist with quarter three being the seasonal high. If the group means are calculated over the entire time span, a rising long-term trend can make later years look elevated at every position and exaggerate a seasonal story. Inspect the original chronological series and, when justified, a separately labeled detrended view. Do not quietly subtract a trend and publish the adjusted trace as raw volume. The seasonal subseries plot is descriptive; a repeated peak does not establish that the calendar position causes it. Keep all panels on one vertical scale so a small within-quarter change is not magnified by a custom axis. Shared-scale panels and event annotations make context visible without overclaiming.
Do not let an unfinished cycle define the reference
A current year with only two complete quarters can contribute those two observed points, but it must not be treated as a four-quarter baseline. Mark its unobserved quarters as missing, not zero, and freeze the complete historical cycles used for the reference means. A backfilled quarter can change the baseline; version that change. The code below requires each reference cycle to contain every position once and permits a later incomplete cycle for display only. Real calendar data also need an explicit policy for holidays, leap days, 53-week years and corrected reports. Counts behind averages belong in the accompanying table. Calendar completeness and missing-cell encoding apply when the same data is shown as a matrix.
Make the grouped view answer a concrete question
For capacity planning, ask whether the same quarter reliably peaks, whether peak magnitude is changing and whether the latest complete point is unusual relative to its own season. A grouped trace can reveal that a conventional time-series line obscures those comparisons. Yet two historical cycles are weak evidence of recurrence; unusual one-off events can dominate a group mean. Show the exact number of complete cycles, use a median reference when outliers are common and inspect sensitivity to leaving out a cycle. Do not project the group mean forward as a forecast without an evaluated model and uncertainty. Forecast fan charts have that different purpose. Provide labels and a reference table for readers who cannot distinguish traces by color alone; accessible chart guidance covers the contract.
Worked contract
from collections import defaultdict
from math import isfinite
def seasonal_subseries(readings: list[tuple[int, int, float]],
positions: int, last_reference_cycle: int):
if positions < 2 or not isinstance(last_reference_cycle, int):
raise ValueError("declare cycle length and reference cutoff")
by_position = defaultdict(list)
seen = set()
reference_cycles = set()
for cycle, position, volume in readings:
if (not isinstance(cycle, int) or not isinstance(position, int) or
not 1 <= position <= positions or not isfinite(volume) or
(cycle, position) in seen):
raise ValueError("cycle positions must be unique, valid and finite")
seen.add((cycle, position))
by_position[position].append((cycle, volume))
if cycle <= last_reference_cycle:
reference_cycles.add(cycle)
if not reference_cycles or any(
(cycle, position) not in seen
for cycle in reference_cycles for position in range(1, positions + 1)):
raise ValueError("every reference cycle must be complete")
result = []
for position in range(1, positions + 1):
trace = sorted(by_position[position])
reference = [volume for cycle, volume in trace
if cycle in reference_cycles]
result.append((position, len(reference), sum(reference) / len(reference), trace))
return result
quarterly_orders = [(47, 1, 47), (47, 2, 59), (47, 3, 83), (47, 4, 71),
(48, 1, 59), (48, 2, 71), (48, 3, 97), (48, 4, 83),
(49, 1, 61), (49, 2, 73)]
panels = seasonal_subseries(quarterly_orders, positions=4,
last_reference_cycle=48)
assert panels[0] == (1, 2, 53.0, [(47, 47), (48, 59), (49, 61)])
assert panels[2] == (3, 2, 90.0, [(47, 83), (48, 97)])
assert panels[3][3] == [(47, 71), (48, 83)]Performance and operating cost
For N readings, validation and grouping take O(N) expected time; sorting each position's trace costs O(sum nₛ log nₛ), bounded by O(N log N). Checking reference completeness takes O(C·S) for C reference cycles and S positions. Stored traces and the duplicate-key set need O(N) space. The toy quarterly ledger uses two complete reference years, giving a first-quarter mean of 53 orders and a third-quarter mean of 90. The partial third year appears only where observed, and never changes the frozen reference. Two cycles verify code behavior but cannot establish dependable seasonality.
Common Mistakes
- Starting the four-position cycle at the wrong fiscal quarter.
- Treating an unobserved current-quarter cell as a measured zero.
- Mixing a trend-adjusted trace with raw-volume reference means without labeling the change.
- Calling a cycle-position mean a validated forecast or causal explanation.
Validation drill
Take 47 completed fiscal years with four quarters each and one partial current year. Audit duplicate and missing quarter keys, show chronological traces for each quarter, calculate references only from complete years, and compare the grouped view with the ungrouped time series.
Read next
- Autocorrelation plots: align equal-spaced periods before reading lag peaks
- Small multiples: compare groups with honest scales and facet order
- Time-series charts: distinguish missing days, zeros and provisional periods
- Forecast fan charts: label interval meaning and forecast horizon
