Heatmap

Temperature Calendar Heatmap

Light theme heatmap showing daily temperatures over months

Output
Temperature Calendar Heatmap
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import FancyBboxPatch

fig, ax = plt.subplots(figsize=(16, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

np.random.seed(42)
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
weeks = [f'W{i+1}' for i in range(26)]
data = 15 + 15 * np.sin(np.linspace(0, np.pi, 26)) + np.random.randn(7, 26) * 3

colors = ['#1e40af', '#60a5fa', '#334155', '#fb923c', '#dc2626']
cmap = LinearSegmentedColormap.from_list('calendar', colors, N=256)

cell_w, cell_h = 0.92, 0.82
for i in range(len(days)):
    for j in range(len(weeks)):
        val = data[i, j]
        rect = FancyBboxPatch((j - cell_w/2, i - cell_h/2), cell_w, cell_h,
                               boxstyle="round,pad=0.01,rounding_size=0.08",
                               facecolor=cmap((val+5)/40), edgecolor='#e2e8f0', linewidth=0.5)
        ax.add_patch(rect)

ax.set_xlim(-0.5, len(weeks)-0.5)
ax.set_ylim(-0.5, len(days)-0.5)
ax.set_aspect('equal')
ax.invert_yaxis()
ax.set_xticks(range(0, len(weeks), 4))
ax.set_yticks(range(len(days)))
ax.set_xticklabels([weeks[i] for i in range(0, len(weeks), 4)], color='#64748b', fontsize=9, fontweight='500')
ax.set_yticklabels(days, color='#1e293b', fontsize=10, fontweight='500')

sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(-5, 35))
cbar = plt.colorbar(sm, ax=ax, shrink=0.8, orientation='horizontal', pad=0.15)
cbar.set_label('Temperature (°C)', color='#1e293b', fontsize=11)
cbar.outline.set_edgecolor('#e2e8f0')
plt.setp(plt.getp(cbar.ax.axes, 'xticklabels'), color='#64748b')

for spine in ax.spines.values(): spine.set_visible(False)
ax.tick_params(length=0)
ax.set_title('Annual Temperature Calendar', fontsize=18, color='#1e293b', fontweight='bold', pad=20)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Heatmaps & Density

Did this help you?

Support PyLucid to keep it free & growing

Support