ANOVA Boxplot
Employee Commute Time ANOVA
Comparing commute durations across different work arrangement types.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
np.random.seed(1616)
# Commute time in minutes (for hybrid/office days)
full_office = np.random.lognormal(3.4, 0.45, 100)
hybrid_3 = np.random.lognormal(3.3, 0.4, 100) # 3 days office
hybrid_2 = np.random.lognormal(3.2, 0.38, 100) # 2 days office
remote = np.zeros(100) + np.random.normal(0, 0.5, 100) # Essentially 0
full_office = np.clip(full_office, 10, 120)
hybrid_3 = np.clip(hybrid_3, 8, 100)
hybrid_2 = np.clip(hybrid_2, 5, 90)
remote = np.clip(remote, 0, 5)
F_stat, p_value = stats.f_oneway(full_office, hybrid_3, hybrid_2, remote)
fig, ax = plt.subplots(figsize=(12, 7), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
colors = ['#F5276C', '#F5B027', '#27D3F5', '#6CF527']
data = [full_office, hybrid_3, hybrid_2, remote]
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 = ['Full Office', 'Hybrid (3d)', 'Hybrid (2d)', 'Remote']
# Stress level correlation
stress = ['High', 'Medium', 'Low', 'Low']
satisfaction = ['68%', '76%', '82%', '85%']
for i, (d, s, sat, color) in enumerate(zip(data, stress, satisfaction, colors)):
ax.text(i+1, -12, f'Stress:{s} | Sat:{sat}', ha='center', fontsize=8, color=color)
# Stats header
stats_text = f"ANOVA: F={F_stat:.1f}, p<0.001 | Weekly hours saved (Remote): {(full_office.mean()*5/60):.1f}h"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#f0fdf4', edgecolor='#6CF527', 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('Daily Commute (minutes)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Work Arrangement Impact on Commute\nEmployee Survey 2024',
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(-20, 130)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More ANOVA Boxplot examples
☕