Raincloud Plot
Blood Pressure by Medication Type
Systolic BP distribution across treatment groups
Output
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt
np.random.seed(201)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#F5276C', '#4927F5', '#6CF527']
meds = ['Placebo', 'Drug A', 'Drug B']
data = pd.DataFrame({
'SystolicBP': np.concatenate([
np.random.normal(145, 15, 80),
np.random.normal(130, 12, 85),
np.random.normal(125, 10, 90)
]),
'Medication': ['Placebo']*80 + ['Drug A']*85 + ['Drug B']*90
})
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
pt.RainCloud(x='Medication', y='SystolicBP', data=data, palette=COLORS,
bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
dodge=True, pointplot=False, move=.2)
ax.axvline(120, color='#22c55e', linestyle='--', alpha=0.6, linewidth=1.5)
ax.text(121, 2.5, 'Normal', color='#22c55e', fontsize=9)
ax.set_xlabel('Systolic BP (mmHg)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Medication', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Blood Pressure by Treatment', 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
More Raincloud Plot examples
☕