Event Plot

Network Packet Analysis

Protocol-level packet timing for network forensics

Output
Network Packet Analysis
Python
import matplotlib.pyplot as plt
import numpy as np

# Simulate network packets
np.random.seed(42)
protocols = ['TCP', 'UDP', 'ICMP', 'HTTP', 'DNS']
packet_times = [
    np.sort(np.random.exponential(0.01, 500).cumsum()),
    np.sort(np.random.exponential(0.02, 300).cumsum()),
    np.sort(np.random.exponential(0.1, 80).cumsum()),
    np.sort(np.random.exponential(0.03, 200).cumsum()),
    np.sort(np.random.exponential(0.05, 150).cumsum()),
]

# Protocol colors
colors = ['#3B82F6', '#10B981', '#F59E0B', '#8B5CF6', '#EC4899']

# Create dark figure
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#111827')
ax.set_facecolor('#111827')

for i, (times, color) in enumerate(zip(packet_times, colors)):
    # Filter to visible range
    visible = times[times <= 8]
    ax.eventplot(visible, lineoffsets=i, linelengths=0.5, linewidths=0.8,
                 colors=color, alpha=0.7)
    
    # Packet count
    ax.text(8.3, i, f'{len(visible)}', fontsize=10, va='center',
            color=color, fontweight='bold')

# Anomaly marker
ax.axvline(5.2, color='#EF4444', linewidth=2, linestyle='--', alpha=0.8)
ax.text(5.3, 4.7, 'Anomaly', fontsize=10, color='#EF4444', fontweight='500')

# Styling
ax.set_yticks(range(len(protocols)))
ax.set_yticklabels(protocols, fontsize=11, fontweight='600', color='white')
ax.set_xlabel('Time (seconds)', fontsize=12, fontweight='500', color='#9CA3AF')
ax.set_xlim(0, 9)
ax.set_ylim(-0.5, len(protocols) - 0.5)

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.xaxis.grid(True, linestyle='--', alpha=0.2, color='#4B5563')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support