Calendar Heatmap

Calorie Intake Calendar

Daily calorie tracking for nutrition and diet management.

Output
Calorie Intake Calendar
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.patches as mpatches

np.random.seed(777)

days = 365
calories = np.random.normal(2000, 400, days).astype(int)
calories = np.clip(calories, 1000, 3500)

# Goal is 2000, show deviation
cal_levels = np.digitize(calories, bins=[0, 1500, 1800, 2000, 2200, 2500]) - 1

weeks = 53
data = np.zeros((7, weeks))
for i, val in enumerate(cal_levels):
    week = i // 7
    day = i % 7
    if week < weeks:
        data[day, week] = val

# Green at target, red at extremes
colors = ['#fef2f2', '#fee2e2', '#bbf7d0', '#22c55e', '#fde68a', '#fecaca']
cmap = LinearSegmentedColormap.from_list('calories', 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('Daily Calorie Intake - Nutrition Tracker', 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, ['<1500', '1500-1800', '1800-2000', '2000-2200', '2200-2500', '>2500'])]
ax.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, -0.15), ncol=6, 
          fontsize=8, facecolor='white', edgecolor='#d1d5db', labelcolor='#374151')

on_target = int(np.sum((calories >= 1800) & (calories <= 2200)))
avg = int(np.mean(calories))
ax.annotate(f'On target: {on_target} days | Avg: {avg:,} cal/day', xy=(0.98, 1.1), xycoords='axes fraction',
            fontsize=10, color='#16a34a', ha='right', fontweight='bold')

plt.tight_layout()
plt.subplots_adjust(bottom=0.25)
plt.show()
Library

Matplotlib

Category

Time Series

Did this help you?

Support PyLucid to keep it free & growing

Support