Violin Plot

Teaching Method Effectiveness

Student performance distribution across pedagogical approaches

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

# Test scores by teaching method
np.random.seed(42)
methods = ['Traditional\nLecture', 'Flipped\nClassroom', 'Project\nBased', 'Gamified\nLearning', 'AI-Assisted\nTutoring']
scores = [
    np.random.normal(72, 12, 120),
    np.random.normal(78, 10, 120),
    np.random.normal(82, 11, 120),
    np.random.normal(80, 9, 120),
    np.random.normal(85, 8, 120),
]

# Colors from cool to warm (effectiveness)
colors = ['#64748B', '#3B82F6', '#8B5CF6', '#F59E0B', '#10B981']

# Create figure
fig, ax = plt.subplots(figsize=(12, 7), facecolor='white')

vp = ax.violinplot(scores, positions=range(len(methods)), widths=0.7,
                   showmeans=False, showmedians=False, showextrema=False)

for i, body in enumerate(vp['bodies']):
    body.set_facecolor(colors[i])
    body.set_edgecolor('white')
    body.set_linewidth(2)
    body.set_alpha(0.7)
    
    # Soft glow
    path = body.get_paths()[0]
    ax.fill(path.vertices[:, 0], path.vertices[:, 1], 
            color=colors[i], alpha=0.15, zorder=0)

# Grade boundaries
grades = [(90, 'A', '#10B981'), (80, 'B', '#22C55E'), 
          (70, 'C', '#F59E0B'), (60, 'D', '#F97316')]
for score, grade, color in grades:
    ax.axhline(score, color=color, linewidth=1, linestyle=':', alpha=0.6)
    ax.text(-0.6, score, grade, fontsize=10, color=color, fontweight='bold', va='center')

# Pass rate (>70) annotations
for i, sc in enumerate(scores):
    median = np.median(sc)
    pass_rate = (sc >= 70).mean() * 100
    a_rate = (sc >= 90).mean() * 100
    
    ax.scatter(i, median, c='white', s=100, zorder=10,
               edgecolor=colors[i], linewidth=2.5)
    
    # Pass rate badge
    ax.text(i, 45, f'{pass_rate:.0f}%', ha='center', fontsize=11,
            color=colors[i], fontweight='bold')
    
    # Effect size vs traditional (Cohen's d approximation)
    if i > 0:
        effect = (np.mean(sc) - np.mean(scores[0])) / np.std(scores[0])
        sign = '+' if effect > 0 else ''
        ax.text(i, 102, f'{sign}{effect:.2f}d', ha='center', fontsize=9,
                color='#10B981' if effect > 0.5 else '#6B7280')

# Labels
ax.text(-0.5, 48, 'Pass Rate', fontsize=9, color='#6B7280')
ax.text(0.5, 104, 'Effect Size vs Traditional', fontsize=9, color='#6B7280')

# Styling
ax.set_xticks(range(len(methods)))
ax.set_xticklabels(methods, fontsize=10, fontweight='500')
ax.set_ylabel('Test Score', fontsize=12, fontweight='500', color='#374151')
ax.set_ylim(40, 110)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#E5E7EB')
ax.spines['bottom'].set_color('#E5E7EB')
ax.tick_params(colors='#6B7280', labelsize=10)
ax.yaxis.grid(True, linestyle='--', alpha=0.3, color='#9CA3AF')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support