ANOVA Boxplot

Network Latency ANOVA Analysis

Comparing packet latency distributions across different network protocols.

Output
Network Latency ANOVA Analysis
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats

np.random.seed(789)

# Latency in microseconds
tcp = np.random.lognormal(4.5, 0.5, 200)
udp = np.random.lognormal(3.8, 0.4, 200)
quic = np.random.lognormal(4.0, 0.35, 200)

tcp = np.clip(tcp, 20, 500)
udp = np.clip(udp, 10, 200)
quic = np.clip(quic, 15, 250)

F_stat, p_value = stats.f_oneway(tcp, udp, quic)

fig, ax = plt.subplots(figsize=(11, 7), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

colors = ['#F5276C', '#6CF527', '#27D3F5']
data = [tcp, udp, quic]

bp = ax.boxplot(data, positions=[1, 2, 3], widths=0.6, patch_artist=True,
                medianprops={'color': 'white', 'linewidth': 2.5},
                whiskerprops={'color': '#555555', 'linewidth': 1.5},
                capprops={'color': '#555555', 'linewidth': 1.5},
                flierprops={'marker': '.', 'markerfacecolor': '#666666', 'markersize': 6})

for patch, color in zip(bp['boxes'], colors):
    patch.set_facecolor(color)
    patch.set_alpha(0.7)
    patch.set_edgecolor('white')
    patch.set_linewidth(2)

# Add jittered points
for i, (d, color) in enumerate(zip(data, colors)):
    x = np.random.normal(i+1, 0.1, len(d))
    ax.scatter(x, d, c=color, alpha=0.2, s=10, zorder=1)

labels = ['TCP', 'UDP', 'QUIC']

# Stats annotations
for i, (d, color) in enumerate(zip(data, colors)):
    ax.text(i+1, -40, f'μ={d.mean():.0f}μs | σ={d.std():.0f}', ha='center', fontsize=9, color=color)

# Jitter threshold
ax.axhline(y=100, color='#fbbf24', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(3.35, 100, 'Target', fontsize=8, color='#fbbf24', va='center')

# Stats header
stats_text = f"ANOVA: F={F_stat:.1f}, p={p_value:.2e} | Lowest Latency: UDP"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#0d1117', edgecolor='#6CF527', lw=2)
ax.text(0.5, 1.02, stats_text, transform=ax.transAxes, fontsize=10, color='white',
        ha='center', va='bottom', fontfamily='monospace', bbox=bbox)

ax.set_xticks([1, 2, 3])
ax.set_xticklabels(labels, fontsize=12, color='white')
ax.set_ylabel('Latency (μs)', fontsize=12, color='white', fontweight='500')
ax.set_title('Network Protocol Latency Comparison\nPacket Round-Trip Time Analysis', 
             fontsize=14, color='white', fontweight='bold', pad=25)

ax.tick_params(colors='#888888')
for spine in ax.spines.values():
    spine.set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_axisbelow(True)
ax.set_ylim(-60, 520)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support