Violin Plot
Raincloud Plot
Combines half-violin, box plot, and scatter for complete distribution view
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Data
np.random.seed(42)
groups = ['Control', 'Treatment A', 'Treatment B']
data = [np.random.normal(5, 1, 80),
np.random.normal(6.5, 1.2, 80),
np.random.normal(7, 0.9, 80)]
# Colors
colors = ['#6366F1', '#10B981', '#F59E0B']
# Create figure
fig, ax = plt.subplots(figsize=(10, 6), facecolor='white')
for i, (d, color) in enumerate(zip(data, colors)):
pos = i * 1.5
# Half violin (right side only)
vp = ax.violinplot([d], positions=[pos], widths=0.6,
showmeans=False, showmedians=False, showextrema=False)
for body in vp['bodies']:
m = np.mean(body.get_paths()[0].vertices[:, 0])
body.get_paths()[0].vertices[:, 0] = np.clip(
body.get_paths()[0].vertices[:, 0], m, np.inf)
body.set_facecolor(color)
body.set_edgecolor('white')
body.set_alpha(0.7)
# Box plot (left side)
bp = ax.boxplot([d], positions=[pos - 0.15], widths=0.12,
patch_artist=True, showfliers=False)
bp['boxes'][0].set_facecolor(color)
bp['boxes'][0].set_alpha(0.9)
bp['medians'][0].set_color('white')
bp['medians'][0].set_linewidth(2)
for element in ['whiskers', 'caps']:
for item in bp[element]:
item.set_color(color)
# Scatter with jitter (rain)
jitter = np.random.uniform(-0.08, 0.08, len(d))
ax.scatter(np.full(len(d), pos - 0.35) + jitter, d,
c=color, s=15, alpha=0.5, edgecolor='none')
# Customize axes
ax.set_xticks([i * 1.5 for i in range(len(groups))])
ax.set_xticklabels(groups, fontsize=11, fontweight='500')
ax.set_ylabel('Response Value', fontsize=12, fontweight='500', color='#374151')
# Clean styling
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
More Violin Plot examples
☕