KDE Plot
Workout Calorie Burn Distribution
KDE comparing calorie expenditure across exercise types.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(109)
running = np.random.normal(450, 100, 400)
cycling = np.random.normal(350, 80, 400)
swimming = np.random.normal(400, 90, 300)
weights = np.random.normal(250, 60, 300)
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
x = np.linspace(50, 700, 500)
exercises = [
(running, 'Running', '#F54927'),
(swimming, 'Swimming', '#27D3F5'),
(cycling, 'Cycling', '#6CF527'),
(weights, 'Weight Training', '#4927F5'),
]
for data, label, color in exercises:
kde = stats.gaussian_kde(data)
y = kde(x)
mean_val = np.mean(data)
ax.fill_between(x, y, alpha=0.25, color=color)
ax.plot(x, y, color=color, linewidth=2.5, label=label + ' (' + str(int(mean_val)) + ' cal)')
ax.set_xlabel('Calories Burned', fontsize=12, color='#1f2937', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Calorie Burn by Exercise Type (1 hour)', fontsize=16, color='#1f2937', fontweight='bold', pad=15)
ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#d1d5db')
ax.legend(loc='upper right', facecolor='#f9fafb', edgecolor='#d1d5db', labelcolor='#374151')
ax.grid(True, alpha=0.3, color='#e5e7eb')
ax.set_xlim(50, 700)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕