Heatmap
Cybersecurity Threat Matrix
Professional heatmap showing threat levels
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
np.random.seed(789)
segments = ['DMZ', 'Internal', 'Cloud', 'IoT', 'Mobile', 'Database', 'API Gateway']
threats = ['Malware', 'DDoS', 'Phishing', 'Injection', 'XSS', 'Zero-Day']
data = np.random.randint(0, 100, (len(segments), len(threats)))
data[0, 0:3] = [85, 92, 78]
data[3, :] = [95, 88, 92, 85, 90, 98]
# Subtle: Light → Pink/Red (danger)
colors = ['#fef2f2', '#fecaca', '#f87171', '#F5276C']
cmap = LinearSegmentedColormap.from_list('SubtleRed', colors, N=256)
fig, ax = plt.subplots(figsize=(12, 9), facecolor='#ffffff')
im = ax.imshow(data, cmap=cmap, aspect='auto', vmin=0, vmax=100)
ax.set_xticks(range(len(threats)))
ax.set_yticks(range(len(segments)))
ax.set_xticklabels(threats, fontsize=10, color='#374151', rotation=45, ha='right')
ax.set_yticklabels(segments, fontsize=11, color='#1f2937', family='monospace')
for i in range(len(segments)):
for j in range(len(threats)):
val = data[i, j]
color = '#ffffff' if val > 75 else '#1f2937'
ax.text(j, i, f'{val}', ha='center', va='center', fontsize=11, fontweight='500', color=color)
cbar = plt.colorbar(im, ax=ax, shrink=0.6, pad=0.02)
cbar.set_label('Threat Level', fontsize=11, color='#1f2937')
cbar.ax.tick_params(labelsize=9, colors='#6b7280')
cbar.outline.set_visible(False)
for spine in ax.spines.values():
spine.set_visible(False)
ax.tick_params(length=0)
ax.set_title('Network Threat Assessment', fontsize=16, color='#1f2937', fontweight='bold', pad=15)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Heatmaps & Density
More Heatmap examples
☕