KDE Plot
Systolic Blood Pressure Distribution
KDE of systolic blood pressure readings with health zones.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(102)
bp = np.random.normal(125, 18, 1000)
bp = bp[(bp > 80) & (bp < 200)]
kde = stats.gaussian_kde(bp)
x = np.linspace(80, 200, 500)
y = kde(x)
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
for i in range(len(x)-1):
if x[i] < 120:
color = '#6CF527'
elif x[i] < 130:
color = '#27D3F5'
elif x[i] < 140:
color = '#F5B027'
else:
color = '#F5276C'
ax.fill_between(x[i:i+2], y[i:i+2], alpha=0.5, color=color)
ax.plot(x, y, color='#27D3F5', linewidth=3)
zones = [(120, 'Normal'), (130, 'Elevated'), (140, 'High'), (180, 'Crisis')]
for val, label in zones:
ax.axvline(val, color='#9ca3af', linestyle='--', linewidth=1.5, alpha=0.7)
ax.set_xlabel('Systolic Blood Pressure (mmHg)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Systolic Blood Pressure Distribution', 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.grid(True, alpha=0.3, color='#e5e7eb')
ax.set_xlim(80, 200)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕