Calendar Heatmap
Focus Time Calendar
Deep work hours tracking for concentration and flow state analysis.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.patches as mpatches
np.random.seed(1010)
days = 365
# Focus hours per day (0-8)
focus = np.zeros(days)
for i in range(days):
dow = i % 7
if dow < 5: # Weekday
focus[i] = np.random.choice([1, 2, 3, 4, 5, 6, 7, 8], p=[0.05, 0.1, 0.15, 0.25, 0.2, 0.15, 0.07, 0.03])
else:
focus[i] = np.random.choice([0, 1, 2, 3], p=[0.4, 0.3, 0.2, 0.1])
focus_levels = np.digitize(focus, bins=[0, 1, 2, 4, 6, 7]) - 1
weeks = 53
data = np.zeros((7, weeks))
for i, val in enumerate(focus_levels):
week = i // 7
day = i % 7
if week < weeks:
data[day, week] = val
colors = ['#ffffff', '#ecfdf5', '#6ee7b7', '#10b981', '#047857', '#064e3b']
cmap = LinearSegmentedColormap.from_list('focus', colors, N=256)
fig, ax = plt.subplots(figsize=(16, 4), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
im = ax.imshow(data, cmap=cmap, aspect='auto', vmin=0, vmax=5)
ax.set_yticks(range(7))
ax.set_yticklabels(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'], fontsize=9, color='#374151')
ax.set_xticks(range(0, 52, 4))
ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', ''],
fontsize=9, color='#374151')
ax.set_title('Deep Focus Time - Flow State Hours', fontsize=16, color='#111827', fontweight='bold', pad=15)
for i in range(8):
ax.axhline(y=i-0.5, color='#e5e7eb', linewidth=0.5)
for i in range(weeks+1):
ax.axvline(x=i-0.5, color='#e5e7eb', linewidth=0.5)
ax.tick_params(colors='#374151', length=0)
for spine in ax.spines.values():
spine.set_visible(False)
legend_elements = [mpatches.Patch(facecolor=c, label=l, edgecolor='#d1d5db')
for c, l in zip(colors, ['<1h', '1-2h', '2-4h', '4-6h', '6-7h', '7h+'])]
ax.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, -0.15), ncol=6,
fontsize=8, facecolor='white', edgecolor='#d1d5db', labelcolor='#374151')
total = int(np.sum(focus))
avg = np.mean(focus[focus > 0])
ax.annotate(f'Total: {total}h | Avg: {avg:.1f}h/work day', xy=(0.98, 1.1), xycoords='axes fraction',
fontsize=10, color='#047857', ha='right', fontweight='bold')
plt.tight_layout()
plt.subplots_adjust(bottom=0.25)
plt.show()
Library
Matplotlib
Category
Time Series
More Calendar Heatmap examples
☕