Generate the full date grid, fix the reporting time zone and encode missing observations separately from zero.
Calendar heatmaps: distinguish an empty day from an absent day
A blank square has several meanings
A calendar heatmap arranges daily values in a weekly grid. A white day could mean zero events, no feed, a day outside the reporting range or a suppressed value. Those states cannot share one silent color. Generate every expected local date first, then join observations and label each cell's status. Missing-cell heatmaps need the same distinction. For a support operation, a zero confirmed ticket count is evidence; an uncollected Saturday is not. Show the number of complete days beside any annual total.
Choose the reporting day
An event at 00:20 UTC may belong to the prior local day. Convert timestamps to the declared reporting zone before aggregating, and record the zone in the export. Daylight-saving changes produce 23- or 25-hour local days in some regions; counts remain counts, but per-hour rates need an exposure adjustment. A calendar grid without its time-zone contract can move incidents across cells and distort weekday patterns. Time-series calendar rules cover incomplete current periods and delayed arrivals. Mark provisional days rather than painting them as final.
Keep color comparable
Fix the numeric color domain across years or related teams when the goal is comparison. Otherwise each year may assign the darkest shade to a different count. If the distribution has a long tail, state any transform or clipped maximum. A daily rate requires the matching daily denominator; weekend exposure often differs from weekday exposure. Grain and denominator come before color selection. A tooltip should expose date, value, status, denominator if used and refresh time, while a text table remains available for keyboard and screen-reader users.
Week structure is a locale decision
Some audiences expect Monday-first weeks; others expect Sunday-first. Label weekdays, show month boundaries and test leap years, year transitions and ISO week edges. Do not infer a causal weekday pattern from a few colored streaks. A release schedule, holiday closure or data-delivery gap may explain the pattern. Event annotations should state what happened without claiming effect. Export an explicit date-status table so another analyst can reconstruct the image rather than reverse-engineering its colors.
Worked contract
from datetime import date, timedelta
def complete_daily_series(start: date, end: date,
observed: dict[date, int | None]
) -> list[tuple[date, str, int | None]]:
if end < start or any(day < start or day > end for day in observed):
raise ValueError("dates must fall inside the requested period")
if any(value is not None and (not isinstance(value, int) or value < 0)
for value in observed.values()):
raise ValueError("daily counts must be nonnegative integers")
result = []
day = start
while day <= end:
value = observed.get(day)
status = "missing" if value is None else "observed"
result.append((day, status, value))
day += timedelta(days=1)
return result
calendar_rows = complete_daily_series(
date(2026, 10, 1), date(2026, 10, 4),
{date(2026, 10, 1): 47, date(2026, 10, 2): 0,
date(2026, 10, 4): 59})
assert calendar_rows[1] == (date(2026, 10, 2), "observed", 0)
assert calendar_rows[2] == (date(2026, 10, 3), "missing", None)Performance and operating cost
For D days and O observed keys, validation and completion take O(D+O) time and O(D) output space. This code assumes the input keys already represent the correct reporting-zone dates; timestamp conversion belongs upstream. If a source uses null to mean suppression rather than missing delivery, give it its own status before calling this function. Store daily exposure separately when coloring rates.
Common Mistakes
- Turning missing days into zeros.
- Aggregating UTC dates and labeling the result as a local calendar.
- Allowing each year to auto-scale its colors during comparison.
- Treating a partly reported current day as final.
Validation drill
Build a 47-day operations calendar with a confirmed zero, a late feed, a holiday closure and one provisional day. Export the four states and explain the color domain.
Read next
- Heatmaps: make missing cells, rates and color domains explicit
- Time-series charts: distinguish missing days, zeros and provisional periods
- Aggregation grain and denominator: make every plotted mark auditable
- Chart annotations: align events to the right clock without claiming causality
