KDE Plot
Workout Duration Distribution
KDE of daily exercise session lengths.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(56)
quick_workouts = np.random.normal(20, 5, 300)
standard = np.random.normal(45, 15, 500)
long_sessions = np.random.normal(90, 20, 200)
duration = np.concatenate([quick_workouts, standard, long_sessions])
duration = duration[duration > 0]
kde = stats.gaussian_kde(duration)
x = np.linspace(0, 150, 500)
y = kde(x)
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
ax.fill_between(x, y, alpha=0.4, color='#6CF527')
ax.plot(x, y, color='#6CF527', linewidth=3)
ax.plot(x, y, color='#6CF527', linewidth=10, alpha=0.15)
ax.axvspan(0, 30, alpha=0.1, color='#27D3F5', label='Quick (0-30min)')
ax.axvspan(30, 60, alpha=0.1, color='#6CF527', label='Standard (30-60min)')
ax.axvspan(60, 150, alpha=0.1, color='#F5B027', label='Extended (60+min)')
ax.axvline(30, color='#F5B027', linestyle='--', linewidth=2)
ax.text(32, max(y)*0.9, 'WHO minimum (30 min)', color='#F5B027', fontsize=9, fontweight='bold')
ax.set_xlabel('Duration (minutes)', fontsize=12, color='white', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='white', fontweight='500')
ax.set_title('Workout Duration Distribution', fontsize=16, color='white', fontweight='bold', pad=15)
ax.tick_params(colors='white', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#334155')
ax.legend(loc='upper right', facecolor='#1e293b', edgecolor='#334155', labelcolor='white')
ax.grid(True, alpha=0.1, color='white')
ax.set_xlim(0, 150)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕