Heatmap
Risk Assessment Heatmap
Light theme heatmap showing risk levels by category
Output
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=(10, 9), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
impact = ['Negligible', 'Minor', 'Moderate', 'Major', 'Severe']
likelihood = ['Rare', 'Unlikely', 'Possible', 'Likely', 'Certain']
data = np.array([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10], [3, 6, 9, 12, 15], [4, 8, 12, 16, 20], [5, 10, 15, 20, 25]])
colors = ['#22c55e', '#84cc16', '#eab308', '#f97316', '#dc2626']
cmap = LinearSegmentedColormap.from_list('risk', colors, N=256)
cell_w, cell_h = 0.88, 0.88
for i in range(5):
for j in range(5):
val = data[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-1)/24), edgecolor='#e2e8f0', linewidth=1.5)
ax.add_patch(rect)
ax.text(j, i, str(val), ha='center', va='center', color='#1e293b', fontsize=12, fontweight='bold')
ax.set_xlim(-0.5, 4.5)
ax.set_ylim(-0.5, 4.5)
ax.set_aspect('equal')
ax.invert_yaxis()
ax.set_xticks(range(5))
ax.set_yticks(range(5))
ax.set_xticklabels(likelihood, rotation=45, ha='right', color='#64748b', fontsize=9, fontweight='500')
ax.set_yticklabels(impact, color='#1e293b', fontsize=10, fontweight='500')
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(1, 25))
cbar = plt.colorbar(sm, ax=ax, shrink=0.8, pad=0.02)
cbar.set_label('Risk Score', 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_xlabel('Likelihood', fontsize=12, color='#64748b', labelpad=10)
ax.set_ylabel('Impact', fontsize=12, color='#64748b', labelpad=10)
ax.set_title('Risk Assessment Matrix', fontsize=18, color='#1e293b', fontweight='bold', pad=20)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Heatmaps & Density
More Heatmap examples
☕