2D Histogram
Cybersecurity Threat Map
Network security visualization showing attack frequency vs response time for threat detection systems.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
# Cybersecurity data
np.random.seed(42)
n_events = 10000
attack_freq = np.random.exponential(5, n_events)
attack_freq = np.clip(attack_freq, 0.1, 50)
base_response = 50 + 20 * np.log1p(attack_freq)
response_time = base_response + np.random.exponential(30, n_events)
response_time = np.clip(response_time, 10, 500)
# Matrix cyber theme
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(10, 8))
fig.patch.set_facecolor('#050808')
ax.set_facecolor('#050808')
# Custom colormap - matrix green
colors = ['#050808', '#081810', '#0a2818', '#0c3820', '#104828',
'#145830', '#187840', '#20a850', '#30d860', '#50ff70', '#80ff90']
cmap = LinearSegmentedColormap.from_list('matrix', colors, N=256)
# 2D histogram
h = ax.hist2d(attack_freq, response_time, bins=50, cmap=cmap, cmin=1)
# SLA thresholds
ax.axhline(y=100, color='#50ff70', linestyle='--', alpha=0.8, linewidth=2, label='SLA Target (100ms)')
ax.axhline(y=200, color='#ffa502', linestyle=':', alpha=0.7, linewidth=1.5, label='Warning (200ms)')
ax.axhline(y=300, color='#ff6b6b', linestyle='--', alpha=0.7, linewidth=1.5, label='Critical (300ms)')
# DDoS zone
ax.axvspan(20, 50, alpha=0.15, color='#ff6b6b', label='DDoS Range')
# Styled colorbar
cbar = plt.colorbar(h[3], ax=ax, pad=0.02, shrink=0.85)
cbar.ax.set_facecolor('#050808')
cbar.set_label('Event Count', fontsize=11, color='#80ff90', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#80ff90')
cbar.outline.set_edgecolor('#185020')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#80ff90', fontsize=9)
ax.set_xlabel('Attack Frequency (events/min)', fontsize=13, color='#80ff90', fontweight='600', labelpad=10)
ax.set_ylabel('Response Time (ms)', fontsize=13, color='#80ff90', fontweight='600', labelpad=10)
ax.set_title('Security Operations - Threat Response', fontsize=16, color='#50ff70', fontweight='bold', pad=20)
ax.tick_params(colors='#50d860', labelsize=10, length=0)
for spine in ax.spines.values():
spine.set_visible(False)
ax.legend(loc='upper left', fontsize=9, facecolor='#081810', edgecolor='#185020', labelcolor='#80ff90')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More 2D Histogram examples
☕