ANOVA Boxplot

Database Query Performance ANOVA

Comparing query execution times across different database engines.

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

np.random.seed(123)

# Query execution time in milliseconds
postgresql = np.random.lognormal(2.5, 0.4, 150)
mysql = np.random.lognormal(2.7, 0.45, 150)
mongodb = np.random.lognormal(2.3, 0.35, 150)
redis = np.random.lognormal(1.2, 0.3, 150)

# Clip for visualization
postgresql = np.clip(postgresql, 2, 80)
mysql = np.clip(mysql, 2, 100)
mongodb = np.clip(mongodb, 2, 60)
redis = np.clip(redis, 0.5, 15)

F_stat, p_value = stats.f_oneway(postgresql, mysql, mongodb, redis)

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

colors = ['#276CF5', '#F5B027', '#6CF527', '#F5276C']
data = [postgresql, mysql, mongodb, redis]

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

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

labels = ['PostgreSQL', 'MySQL', 'MongoDB', 'Redis']

# Percentile annotations
for i, (d, color) in enumerate(zip(data, colors)):
    p50 = np.percentile(d, 50)
    p99 = np.percentile(d, 99)
    ax.text(i+1, -8, f'P50:{p50:.1f} P99:{p99:.1f}', ha='center', fontsize=8, color=color)

# Performance threshold
ax.axhline(y=50, color='#ef4444', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(4.45, 50, 'SLA', fontsize=8, color='#ef4444', va='center')

# Stats header
stats_text = f"ANOVA: F={F_stat:.1f}, p<0.001 | Fastest: Redis (μ={redis.mean():.1f}ms)"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#020B14', edgecolor='#F5276C', 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, 4])
ax.set_xticklabels(labels, fontsize=11, color='white')
ax.set_ylabel('Query Time (ms)', fontsize=12, color='white', fontweight='500')
ax.set_title('Database Engine Performance Comparison\nSELECT Query Benchmark', 
             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(-15, 110)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support