ANOVA Boxplot
Shipping Carrier Delivery ANOVA
Comparing delivery times across major shipping carriers.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
np.random.seed(1818)
# Delivery time in days
fedex = np.random.lognormal(0.8, 0.3, 150)
ups = np.random.lognormal(0.85, 0.32, 150)
usps = np.random.lognormal(1.0, 0.4, 150)
dhl = np.random.lognormal(0.9, 0.35, 150)
fedex = np.clip(fedex, 1, 8)
ups = np.clip(ups, 1, 9)
usps = np.clip(usps, 1, 12)
dhl = np.clip(dhl, 1, 10)
F_stat, p_value = stats.f_oneway(fedex, ups, usps, dhl)
fig, ax = plt.subplots(figsize=(12, 7), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
colors = ['#4927F5', '#F5B027', '#276CF5', '#F5276C']
data = [fedex, ups, usps, dhl]
bp = ax.boxplot(data, positions=[1, 2, 3, 4], widths=0.6, patch_artist=True,
medianprops={'color': '#1f2937', 'linewidth': 2},
whiskerprops={'color': '#9ca3af', 'linewidth': 1.5},
capprops={'color': '#9ca3af', 'linewidth': 1.5},
flierprops={'marker': 'o', 'markerfacecolor': '#d1d5db', 'markersize': 4})
for patch, color in zip(bp['boxes'], colors):
patch.set_facecolor(color)
patch.set_alpha(0.6)
patch.set_edgecolor(color)
patch.set_linewidth(2)
labels = ['FedEx', 'UPS', 'USPS', 'DHL']
# On-time delivery rate
ontime = ['94%', '92%', '85%', '91%']
for i, (d, ot, color) in enumerate(zip(data, ontime, colors)):
ax.text(i+1, -0.5, f'On-time: {ot}', ha='center', fontsize=9, color=color, fontweight='bold')
# Standard shipping promise
ax.axhline(y=3, color='#22c55e', linestyle='--', alpha=0.6, linewidth=1.5)
ax.axhline(y=5, color='#fbbf24', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(4.45, 3, 'Express', fontsize=7, color='#22c55e', va='center')
ax.text(4.45, 5, 'Standard', fontsize=7, color='#fbbf24', va='center')
# Stats header
stats_text = f"ANOVA: F={F_stat:.2f}, p={p_value:.4f} | Fastest: FedEx (μ={fedex.mean():.1f} days)"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#eff6ff', edgecolor='#4927F5', 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('Delivery Time (days)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Shipping Carrier Performance\nGround Shipping Comparison',
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, 13)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More ANOVA Boxplot examples
☕