Raincloud Plot
Vaccine Protection Rate by Demographics
Protection rates across age demographics
Output
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt
np.random.seed(220)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
COLORS = ['#6CF527', '#27D3F5', '#F5B027', '#F5276C']
ages = ['18-30', '31-50', '51-65', '65+']
data = pd.DataFrame({
'Efficacy': np.concatenate([
np.random.beta(45, 5, 90) * 100,
np.random.beta(42, 6, 100) * 100,
np.random.beta(38, 7, 85) * 100,
np.random.beta(35, 8, 75) * 100
]),
'Age': ['18-30']*90 + ['31-50']*100 + ['51-65']*85 + ['65+']*75
})
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
pt.RainCloud(x='Age', y='Efficacy', 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, 'Target', color='#22c55e', fontsize=9)
ax.set_xlabel('Protection Rate (%)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Age Group', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Vaccine Protection by Age', 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
☕