Raincloud Plot
Battery Life by Smartphone Brand
Screen-on time distribution across phone brands
Output
Python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import ptitprince as pt
np.random.seed(115)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
COLORS = ['#27D3F5', '#6CF527', '#F5276C', '#F5B027']
brands = ['Apple', 'Samsung', 'Google', 'OnePlus']
data = pd.DataFrame({
'SOT': np.concatenate([
np.random.normal(7.5, 1.2, 80),
np.random.normal(8.2, 1.5, 85),
np.random.normal(6.8, 1.0, 75),
np.random.normal(9.0, 1.8, 70)
]),
'Brand': ['Apple']*80 + ['Samsung']*85 + ['Google']*75 + ['OnePlus']*70
})
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
pt.RainCloud(x='Brand', y='SOT', data=data, palette=COLORS,
bw=.2, width_viol=.6, ax=ax, orient='h', alpha=.65,
dodge=True, pointplot=False, move=.2)
ax.set_xlabel('Screen-On Time (hours)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Brand', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Smartphone Battery Life by Brand', 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
☕