Heatmap

Weather Pattern Heatmap

Light theme heatmap showing weather conditions

Output
Weather Pattern 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=(14, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

np.random.seed(42)
cities = ['NYC', 'LA', 'Chicago', 'Houston', 'Phoenix', 'Seattle']
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
temps = np.array([
    [2, 4, 10, 16, 21, 26, 29, 28, 24, 17, 11, 5],
    [15, 16, 17, 18, 20, 22, 25, 26, 25, 22, 18, 15],
    [-3, -1, 5, 12, 18, 24, 27, 26, 22, 14, 6, -1],
    [12, 14, 18, 22, 26, 29, 30, 30, 28, 23, 17, 13],
    [14, 16, 20, 25, 30, 36, 39, 38, 35, 27, 19, 14],
    [6, 7, 9, 12, 15, 18, 21, 21, 18, 13, 8, 5]
])

colors = ['#1e40af', '#3b82f6', '#334155', '#fb923c', '#dc2626']
cmap = LinearSegmentedColormap.from_list('temp', colors, N=256)

cell_w, cell_h = 0.88, 0.82
for i in range(len(cities)):
    for j in range(len(months)):
        val = temps[i, j]
        rect = FancyBboxPatch((j - cell_w/2, i - cell_h/2), cell_w, cell_h,
                               boxstyle="round,pad=0.02,rounding_size=0.12",
                               facecolor=cmap((val+10)/55), edgecolor='#e2e8f0', linewidth=1.5)
        ax.add_patch(rect)
        ax.text(j, i, f'{val}°', ha='center', va='center', color='#1e293b', fontsize=9, fontweight='bold')

ax.set_xlim(-0.5, len(months)-0.5)
ax.set_ylim(-0.5, len(cities)-0.5)
ax.set_aspect('equal')
ax.invert_yaxis()
ax.set_xticks(range(len(months)))
ax.set_yticks(range(len(cities)))
ax.set_xticklabels(months, color='#64748b', fontsize=9, fontweight='500')
ax.set_yticklabels(cities, color='#1e293b', fontsize=10, fontweight='500')

sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(-10, 45))
cbar = plt.colorbar(sm, ax=ax, shrink=0.8, pad=0.02)
cbar.set_label('Temperature (°C)', color='#1e293b', fontsize=11)
cbar.outline.set_edgecolor('#e2e8f0')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#64748b')

for spine in ax.spines.values(): spine.set_visible(False)
ax.tick_params(length=0)
ax.set_title('Average Monthly Temperatures', 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