In risk assessments, priority is often set by likelihood and impact. A heatmap matrix makes urgent items obvious at a glance.
import numpy as np
import matplotlib.pyplot as plt
levels = ["Low", "Somewhat low", "Medium", "Somewhat high", "High"]
impact = ["Minor", "Limited", "Moderate", "Severe", "Critical"]
risk_matrix = np.array(
[
[1, 1, 2, 3, 4],
[1, 2, 2, 3, 4],
[2, 2, 3, 4, 4],
[2, 3, 4, 4, 5],
[3, 4, 4, 5, 5],
]
)
fig, ax = plt.subplots(figsize=(5.8, 5.2))
im = ax.imshow(risk_matrix, cmap="YlOrRd", vmin=1, vmax=5)
ax.set_xticks(range(len(levels)), labels=levels)
ax.set_yticks(range(len(impact)), labels=impact)
ax.set_xlabel("Likelihood")
ax.set_ylabel("Impact")
ax.set_title("Risk matrix")
for i in range(risk_matrix.shape[0]):
for j in range(risk_matrix.shape[1]):
risk = risk_matrix[i, j]
color = "white" if risk >= 4 else "#0f172a"
ax.text(j, i, risk, ha="center", va="center", color=color, fontsize=12)
cbar = fig.colorbar(im, ax=ax, fraction=0.046, pad=0.04)
cbar.set_label("Priority level", rotation=270, labelpad=15)
ax.set_xticks(np.arange(-0.5, 5, 1), minor=True)
ax.set_yticks(np.arange(-0.5, 5, 1), minor=True)
ax.grid(which="minor", color="white", linewidth=1.5)
ax.tick_params(which="minor", bottom=False, left=False)
fig.tight_layout()
plt.show()

Reading tips #
- Cells near the top-right (red) are highest priority and guide risk mitigation order.
- Add simple rules such as “monitor only” for the low-risk region.
- Numbered cells make it easier to link to detailed tickets or tables.