ANOVA Boxplot

Emergency Room Wait Time ANOVA

Comparing patient wait times across different hospital emergency departments.

Output
Emergency Room Wait Time ANOVA
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats

np.random.seed(1212)

# Wait time in minutes
urban_public = np.random.lognormal(4.2, 0.5, 150)
urban_private = np.random.lognormal(3.5, 0.4, 150)
suburban = np.random.lognormal(3.8, 0.45, 150)
rural = np.random.lognormal(3.2, 0.35, 150)

urban_public = np.clip(urban_public, 15, 300)
urban_private = np.clip(urban_private, 10, 150)
suburban = np.clip(suburban, 12, 200)
rural = np.clip(rural, 8, 100)

F_stat, p_value = stats.f_oneway(urban_public, urban_private, suburban, rural)

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

colors = ['#C82909', '#F5B027', '#27D3F5', '#6CF527']
data = [urban_public, urban_private, suburban, rural]

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': '.', 'markerfacecolor': '#d1d5db', 'markersize': 5})

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 = ['Urban Public', 'Urban Private', 'Suburban', 'Rural']

# Target wait time
ax.axhline(y=60, color='#22c55e', linestyle='--', alpha=0.7, linewidth=1.5)
ax.axhline(y=120, color='#ef4444', linestyle='--', alpha=0.7, linewidth=1.5)
ax.text(4.45, 60, 'Target', fontsize=7, color='#22c55e', va='center')
ax.text(4.45, 120, 'Critical', fontsize=7, color='#ef4444', va='center')

# Patient satisfaction
satisfaction = ['62%', '78%', '71%', '85%']
for i, (d, sat, color) in enumerate(zip(data, satisfaction, colors)):
    ax.text(i+1, -25, f'Satisfaction: {sat}', ha='center', fontsize=8, color=color)

# Stats header
stats_text = f"ANOVA: F={F_stat:.1f}, p<0.001 | Shortest Wait: Rural (μ={rural.mean():.0f} min)"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#fef2f2', edgecolor='#C82909', 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('Wait Time (minutes)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Emergency Department Wait Times\nRegional Hospital 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(-40, 320)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support