ANOVA Violin Plot

Teaching Method Effectiveness ANOVA

Comparing student test score distributions across different pedagogical approaches.

Output
Teaching Method Effectiveness ANOVA
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats

np.random.seed(1111)

# Test scores (0-100) by teaching method
traditional = np.random.normal(72, 12, 120)
flipped = np.random.normal(78, 10, 120)
project_based = np.random.normal(81, 11, 120)
hybrid = np.random.normal(76, 9, 120)

F_stat, p_value = stats.f_oneway(traditional, flipped, project_based, hybrid)

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

colors = ['#4927F5', '#27D3F5', '#6CF527', '#F5B027']

parts = ax.violinplot([traditional, flipped, project_based, hybrid], 
                       positions=[1, 2, 3, 4], showmeans=True, showmedians=True, widths=0.7)

for i, pc in enumerate(parts['bodies']):
    pc.set_facecolor(colors[i])
    pc.set_alpha(0.6)
    pc.set_edgecolor(colors[i])
    pc.set_linewidth(2)

parts['cmeans'].set_color('#F5276C')
parts['cmeans'].set_linewidth(2.5)
parts['cmedians'].set_color('#1f2937')
for partname in ['cbars', 'cmins', 'cmaxes']:
    parts[partname].set_color('#9ca3af')

# Pass threshold
ax.axhline(y=60, color='#ef4444', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(4.45, 60, 'Pass', fontsize=9, color='#ef4444', va='center')

# Grade A zone
ax.axhspan(90, 105, alpha=0.1, color='#22c55e')

labels = ['Traditional\nLecture', 'Flipped\nClassroom', 'Project-\nBased', 'Hybrid\nModel']
means = [traditional.mean(), flipped.mean(), project_based.mean(), hybrid.mean()]

# Mean annotations at bottom
for i, (mean, color) in enumerate(zip(means, colors)):
    ax.text(i+1, 35, f'μ={mean:.1f}', ha='center', fontsize=10, color=color, fontweight='bold')

# Stats box - top center
stats_text = f"ANOVA: F={F_stat:.2f}, p={p_value:.4f} | Best: Project-Based"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#f8fafc', edgecolor='#6CF527', lw=2)
ax.text(0.5, 1.02, stats_text, transform=ax.transAxes, fontsize=10, color='#1f2937',
        ha='center', va='bottom', fontfamily='monospace', bbox=bbox)

ax.set_xticks([1, 2, 3, 4])
ax.set_xticklabels(labels, fontsize=10, color='#1f2937')
ax.set_ylabel('Test Score', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Student Performance by Teaching Method\nEducational Effectiveness Study (N=480)', 
             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(30, 110)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support