Violin Plot
Network Anomaly Detection
Response time patterns for threat classification
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Network response time data (ms)
np.random.seed(42)
traffic_types = ['Normal', 'DDoS', 'Port Scan', 'SQL Injection', 'Brute Force']
response_times = [
np.random.gamma(2, 5, 400), # Normal - low
np.random.gamma(15, 8, 400) + 50, # DDoS - high latency
np.random.exponential(15, 400) + 5, # Port scan - variable
np.random.normal(25, 8, 400), # SQL injection - moderate
np.random.gamma(4, 12, 400) + 20, # Brute force - spiky
]
# Threat level colors
colors = ['#10B981', '#EF4444', '#F97316', '#8B5CF6', '#EC4899']
# Create dark security dashboard theme
fig, ax = plt.subplots(figsize=(12, 7), facecolor='#111827')
ax.set_facecolor('#111827')
vp = ax.violinplot(response_times, positions=range(len(traffic_types)), widths=0.7,
showmeans=False, showmedians=False, showextrema=False)
for i, body in enumerate(vp['bodies']):
body.set_facecolor(colors[i])
body.set_edgecolor(colors[i])
body.set_linewidth(1)
body.set_alpha(0.25)
# Neon glow
path = body.get_paths()[0]
for lw, alpha in [(12, 0.05), (8, 0.1), (4, 0.2), (2, 0.5)]:
ax.plot(path.vertices[:, 0], path.vertices[:, 1],
color=colors[i], linewidth=lw, alpha=alpha)
# Alert threshold
threshold = 50
ax.axhline(threshold, color='#FBBF24', linewidth=2, linestyle='--', alpha=0.7)
ax.fill_between([-0.5, 4.5], threshold, 200, color='#FBBF24', alpha=0.05)
ax.text(4.55, threshold + 5, 'ALERT', fontsize=10, color='#FBBF24',
fontweight='bold', va='bottom')
# Detection stats
for i, times in enumerate(response_times):
median = np.median(times)
alert_pct = (times > threshold).mean() * 100
# Glowing median
for s, a in [(120, 0.2), (80, 0.4), (40, 0.8)]:
ax.scatter(i, median, c=colors[i], s=s, alpha=a, zorder=10)
ax.scatter(i, median, c='white', s=20, zorder=11)
# Alert percentage
if alert_pct > 10:
ax.text(i, 180, f'{alert_pct:.0f}%', ha='center', fontsize=11,
color='#EF4444', fontweight='bold')
# Threat level badges
threat_levels = ['LOW', 'CRITICAL', 'HIGH', 'MEDIUM', 'HIGH']
badge_colors = ['#10B981', '#EF4444', '#F97316', '#FBBF24', '#F97316']
for i, (level, color) in enumerate(zip(threat_levels, badge_colors)):
ax.text(i, -15, level, ha='center', fontsize=8, fontweight='bold',
color=color, bbox=dict(boxstyle='round,pad=0.3',
facecolor='#1F2937', edgecolor=color, linewidth=1.5))
# Styling
ax.set_xticks(range(len(traffic_types)))
ax.set_xticklabels(traffic_types, fontsize=10, fontweight='600', color='#E5E7EB')
ax.set_ylabel('Response Time (ms)', fontsize=12, fontweight='500', color='#9CA3AF')
ax.set_ylim(-25, 200)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#374151')
ax.spines['bottom'].set_color('#374151')
ax.tick_params(colors='#9CA3AF', labelsize=10)
ax.yaxis.grid(True, linestyle='--', alpha=0.15, color='#4B5563')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Violin Plot examples
☕