Raincloud Plot
Sleep Quality Score by Age Group
Sleep assessment scores across demographics
Output
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt
np.random.seed(109)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
COLORS = ['#276CF5', '#6CF527', '#F5B027', '#F5276C']
ages = ['18-30', '31-45', '46-60', '60+']
data = pd.DataFrame({
'Score': np.concatenate([
np.random.normal(78, 12, 100),
np.random.normal(72, 14, 110),
np.random.normal(65, 15, 95),
np.random.normal(60, 16, 85)
]),
'Age': ['18-30']*100 + ['31-45']*110 + ['46-60']*95 + ['60+']*85
})
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
pt.RainCloud(x='Age', y='Score', data=data, palette=COLORS,
bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
dodge=True, pointplot=False, move=.2)
ax.set_xlabel('Sleep Quality Score', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Age Group', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Sleep Quality by Age Group', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.tick_params(colors='#888', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#333')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Raincloud Plot examples
☕