Raincloud Plot

Student Test Scores by Study Method

Exam performance across learning approaches

Output
Student Test Scores by Study Method
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt

np.random.seed(203)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#F54927', '#4927F5', '#27F5B0', '#F5D327']

methods = ['Traditional', 'Online', 'Hybrid', 'Self-Paced']
data = pd.DataFrame({
    'Score': np.concatenate([
        np.random.normal(72, 12, 90),
        np.random.normal(75, 14, 85),
        np.random.normal(80, 10, 95),
        np.random.normal(68, 16, 80)
    ]),
    'Method': ['Traditional']*90 + ['Online']*85 + ['Hybrid']*95 + ['Self-Paced']*80
})

fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

pt.RainCloud(x='Method', y='Score', data=data, palette=COLORS,
             bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
             dodge=True, pointplot=False, move=.2)

ax.axvline(70, color='#22c55e', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(71, 3.5, 'Pass', color='#22c55e', fontsize=9)

ax.set_xlabel('Test Score', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Study Method', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Student Performance by Study Method', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support