ANOVA Violin Plot

Browser Performance ANOVA

Comparing website rendering speeds across different web browsers.

Output
Browser Performance ANOVA
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats

np.random.seed(1919)

# Page load time in seconds
chrome = np.random.lognormal(0.4, 0.3, 150)
firefox = np.random.lognormal(0.5, 0.35, 150)
safari = np.random.lognormal(0.35, 0.25, 150)
edge = np.random.lognormal(0.45, 0.32, 150)

# Clip for realistic values
chrome = np.clip(chrome, 0.5, 8)
firefox = np.clip(firefox, 0.5, 10)
safari = np.clip(safari, 0.4, 6)
edge = np.clip(edge, 0.5, 9)

F_stat, p_value = stats.f_oneway(chrome, firefox, safari, edge)

fig, ax = plt.subplots(figsize=(12, 7), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

colors = ['#F5B027', '#F5276C', '#27D3F5', '#276CF5']

parts = ax.violinplot([chrome, firefox, safari, edge], 
                       positions=[1, 2, 3, 4], showmeans=True, showmedians=True, widths=0.7)

for i, pc in enumerate(parts['bodies']):
    pc.set_facecolor(colors[i])
    pc.set_alpha(0.6)
    pc.set_edgecolor(colors[i])
    pc.set_linewidth(2)

parts['cmeans'].set_color('#6CF527')
parts['cmeans'].set_linewidth(2.5)
parts['cmedians'].set_color('#1f2937')
for partname in ['cbars', 'cmins', 'cmaxes']:
    parts[partname].set_color('#9ca3af')

# Performance thresholds
ax.axhline(y=2.0, color='#22c55e', linestyle='--', alpha=0.7, linewidth=1.5)
ax.axhline(y=4.0, color='#f97316', linestyle='--', alpha=0.7, linewidth=1.5)
ax.text(4.45, 2.0, 'Good', fontsize=8, color='#22c55e', va='center')
ax.text(4.45, 4.0, 'Slow', fontsize=8, color='#f97316', va='center')

# Zone coloring
ax.axhspan(0, 2, alpha=0.08, color='#22c55e')
ax.axhspan(2, 4, alpha=0.05, color='#fbbf24')

labels = ['Chrome', 'Firefox', 'Safari', 'Edge']
means = [chrome.mean(), firefox.mean(), safari.mean(), edge.mean()]

# Market share and mean at bottom
market_share = ['65%', '8%', '18%', '5%']
for i, (share, mean, color) in enumerate(zip(market_share, means, colors)):
    ax.text(i+1, -0.8, f'{share} | μ={mean:.2f}s', ha='center', fontsize=9, color=color)

# Stats at top
stats_text = f"ANOVA: F={F_stat:.2f}, p={p_value:.4f} | Fastest: Safari (μ={safari.mean():.2f}s)"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#eff6ff', edgecolor='#276CF5', lw=2)
ax.text(0.5, 1.02, stats_text, transform=ax.transAxes, fontsize=9, color='#1f2937',
        ha='center', va='bottom', fontfamily='monospace', bbox=bbox)

ax.set_xticks([1, 2, 3, 4])
ax.set_xticklabels(labels, fontsize=11, color='#1f2937')
ax.set_ylabel('Page Load Time (seconds)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Web Browser Performance Comparison\nCore Web Vitals Benchmark', 
             fontsize=14, color='#1f2937', fontweight='bold', pad=25)

ax.tick_params(colors='#374151')
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')
ax.yaxis.grid(True, color='#f3f4f6', linewidth=0.8)
ax.set_axisbelow(True)
ax.set_ylim(-1.2, 10)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support