Ridgeline Plot
Battery Drain by App
Battery consumption distributions for different apps
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(42)
apps = ['Gaming', 'Video', 'Social', 'Browser', 'Music']
colors = ['#F5276C', '#F54927', '#27D3F5', '#6CF527', '#F5B027']
# Generate battery drain data (% per hour)
data = {
'Gaming': np.random.gamma(5, 3, 350),
'Video': np.random.gamma(4, 2.5, 350),
'Social': np.random.gamma(2.5, 2, 350),
'Browser': np.random.gamma(2, 1.8, 350),
'Music': np.random.gamma(1.5, 1.5, 350)
}
fig, ax = plt.subplots(figsize=(12, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
overlap = 2.2
x_range = np.linspace(0, 35, 300)
for i, (app, drain) in enumerate(data.items()):
kde = stats.gaussian_kde(drain, bw_method=0.3)
y = kde(x_range) * 9
baseline = i * overlap
ax.fill_between(x_range, baseline, y + baseline,
alpha=0.75, color=colors[i], linewidth=0)
ax.plot(x_range, y + baseline, color=colors[i], linewidth=2)
ax.text(-1, baseline + 0.3, app, fontsize=11, color='#1f2937',
ha='right', va='bottom', fontweight='500')
ax.set_xlim(-6, 35)
ax.set_ylim(-0.5, len(apps) * overlap + 1.5)
ax.set_xlabel('Battery Drain (% per hour)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Battery Drain by App Category', fontsize=16, color='#1f2937',
fontweight='bold', pad=20)
ax.tick_params(axis='x', colors='#374151', labelsize=10)
ax.tick_params(axis='y', left=False, labelleft=False)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_color('#e5e7eb')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Ridgeline Plot examples
☕