ANOVA Boxplot
Wine Quality by Region ANOVA
Comparing wine quality scores across famous wine-producing regions.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
np.random.seed(2020)
# Wine quality score (1-100, Wine Spectator scale)
bordeaux = np.random.normal(91, 3.5, 80)
napa = np.random.normal(90, 4, 80)
tuscany = np.random.normal(89, 3.8, 80)
rioja = np.random.normal(87, 4.2, 80)
burgundy = np.random.normal(92, 3.2, 80)
bordeaux = np.clip(bordeaux, 78, 100)
napa = np.clip(napa, 76, 99)
tuscany = np.clip(tuscany, 75, 98)
rioja = np.clip(rioja, 72, 96)
burgundy = np.clip(burgundy, 80, 100)
F_stat, p_value = stats.f_oneway(bordeaux, napa, tuscany, rioja, burgundy)
fig, ax = plt.subplots(figsize=(13, 7), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
colors = ['#9C2007', '#6CF527', '#C82909', '#F5B027', '#4927F5']
data = [bordeaux, napa, tuscany, rioja, burgundy]
bp = ax.boxplot(data, positions=[1, 2, 3, 4, 5], widths=0.55, 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 = ['Bordeaux', 'Napa Valley', 'Tuscany', 'Rioja', 'Burgundy']
# Quality thresholds
ax.axhspan(90, 100, alpha=0.08, color='#22c55e')
ax.axhline(y=90, color='#22c55e', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(5.45, 90, 'Outstanding', fontsize=7, color='#22c55e', va='center')
# Average price
prices = ['$85', '$65', '$55', '$35', '$120']
for i, (d, price, color) in enumerate(zip(data, prices, colors)):
ax.text(i+1, 70, f'μ={d.mean():.1f} | {price}', ha='center', fontsize=8, color=color)
# Stats header
stats_text = f"ANOVA: F={F_stat:.2f}, p={p_value:.4f} | Top Region: Burgundy (μ={burgundy.mean():.1f})"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#fef2f2', edgecolor='#9C2007', 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, 5])
ax.set_xticklabels(labels, fontsize=10, color='#1f2937')
ax.set_ylabel('Wine Spectator Score', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Wine Quality by Region\n2023 Vintage Ratings',
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(68, 102)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More ANOVA Boxplot examples
☕