Project 33: Calendar Heatmap Diary 📅¶

Difficulty: 🟡 Intermediate

Run cells top to bottom. Each step builds on the previous one and saves real files under outputs/calendar_heatmap_diary/.

← Back to index

Description¶

Fake a month of productivity scores and render a GitHub-style calendar heatmap.

Libraries & Modules¶

  • numpy, matplotlib
  • datetime

Python Concepts You'll Practice¶

Date ranges, mesh grids, heatmap visualization

🎛️ Parameter Variations¶

  • YEAR, MONTH
  • SEED for random productivity
In [1]:
# Install dependencies for this project (safe to re-run)
import sys
!{sys.executable} -m pip install pillow numpy matplotlib wordcloud qrcode[pil] python-barcode fpdf2 jinja2 folium plotly pandas scipy ipywidgets -q
Skipping pip install (already installed)
In [2]:
# Interactive Jupyter setup — run this cell first
%matplotlib inline

from pathlib import Path
from IPython.display import display, Image as IPImage, HTML, Markdown, Audio, IFrame

OUTPUT_DIR = Path("outputs") / "calendar_heatmap_diary"
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
print(f"✅ Outputs folder: {OUTPUT_DIR.resolve()}")
✅ Outputs folder: C:\Users\Hansel Yan\Projects\CodeItAll\outputs\calendar_heatmap_diary

Step 1 — Invent a month of scores¶

In [3]:
from datetime import date
import calendar
import numpy as np

# 🎛️ TWEAK THESE
YEAR, MONTH = 2026, 7
SEED = 17

rng = np.random.default_rng(SEED)
weeks = calendar.monthcalendar(YEAR, MONTH)
scores = []
for week in weeks:
    row = []
    for day in week:
        if day == 0:
            row.append(np.nan)
        else:
            row.append(float(rng.integers(0, 5)))
    scores.append(row)
scores = np.array(scores, dtype=float)
print(scores)
[[nan nan  3.  4.  0.  0.  2.]
 [ 2.  3.  1.  0.  1.  2.  1.]
 [ 4.  2.  3.  3.  0.  3.  0.]
 [ 0.  2.  1.  1.  3.  0.  0.]
 [ 3.  4.  3.  4.  2. nan nan]]

Step 2 — Draw the heatmap¶

In [4]:
import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(8, 3.2))
im = ax.imshow(scores, cmap="YlOrRd", aspect="auto", vmin=0, vmax=4)
ax.set_xticks(range(7), ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"])
ax.set_yticks(range(len(scores)), [f"W{i+1}" for i in range(len(scores))])
ax.set_title(f"Calendar Heatmap Diary — {calendar.month_name[MONTH]} {YEAR}")
fig.colorbar(im, ax=ax, label="Productivity")
fig.tight_layout()
out = OUTPUT_DIR / "calendar_heatmap.png"
fig.savefig(out, dpi=150)
plt.show()
print(f"Saved {out}")
No description has been provided for this image
Saved outputs\calendar_heatmap_diary\calendar_heatmap.png

✅ Project complete¶

Check your output folder: outputs/calendar_heatmap_diary/

Next: Project 34: Flashcard Forge · Index