KDE Plot
Resting Heart Rate Distribution
KDE of resting heart rate with fitness level zones.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(51)
# Heart rate distribution
hr = np.random.normal(72, 12, 1000)
hr = hr[(hr > 40) & (hr < 110)]
kde = stats.gaussian_kde(hr)
x = np.linspace(40, 110, 500)
y = kde(x)
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
# Gradient fill based on health zones
for i in range(len(x)-1):
if x[i] < 60:
color = '#27D3F5' # Athletic - cyan
elif x[i] < 70:
color = '#6CF527' # Excellent - lime
elif x[i] < 80:
color = '#27F5B0' # Good - mint
elif x[i] < 90:
color = '#F5B027' # Average - amber
else:
color = '#F5276C' # High - coral
ax.fill_between(x[i:i+2], y[i:i+2], alpha=0.6, color=color)
ax.plot(x, y, color='#4927F5', linewidth=3)
ax.plot(x, y, color='#4927F5', linewidth=8, alpha=0.2)
# Zone labels at top
zones = [(50, 'Athletic'), (65, 'Excellent'), (75, 'Good'), (85, 'Average'), (100, 'High')]
for pos, label in zones:
ax.text(pos, max(y)*1.05, label, color='#e2e8f0', fontsize=9, ha='center', fontweight='bold')
ax.set_xlabel('Resting Heart Rate (BPM)', fontsize=12, color='white', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='white', fontweight='500')
ax.set_title('Resting Heart Rate 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.grid(True, alpha=0.1, color='white')
ax.set_xlim(40, 110)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕