KDE Plot

Patient Wait Time Cumulative KDE

Cumulative distribution of patient wait times by clinic type

Output
Patient Wait Time Cumulative KDE
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde

np.random.seed(1111)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
GRID_COLOR = '#e5e7eb'

# Wait time in minutes
urgent_care = np.random.exponential(15, 400) + 5
primary = np.random.exponential(25, 400) + 10
specialist = np.random.exponential(35, 400) + 15

fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

x_range = np.linspace(0, 150, 500)

for data, color, label in [(urgent_care, '#F5276C', 'Urgent Care'), 
                            (primary, '#27D3F5', 'Primary Care'),
                            (specialist, '#F5B027', 'Specialist')]:
    kde = gaussian_kde(data)
    cdf = np.array([kde.integrate_box_1d(-np.inf, x) for x in x_range])
    ax.plot(x_range, cdf, color=color, linewidth=3, label=label)

ax.axvline(30, color='#22c55e', linestyle='--', alpha=0.7, linewidth=2)
ax.text(32, 0.3, '30min Target', color='#22c55e', fontsize=10)

ax.set_xlabel('Wait Time (minutes)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Cumulative Probability', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Patient Wait Time: Cumulative Distribution', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

ax.tick_params(colors=TEXT_COLOR, labelsize=10)
for spine in ax.spines.values():
    spine.set_color(GRID_COLOR)
ax.yaxis.grid(True, color=GRID_COLOR, linewidth=0.5, alpha=0.7)
ax.legend(facecolor=BG_COLOR, edgecolor=GRID_COLOR, labelcolor=TEXT_COLOR, fontsize=10, loc='lower right')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support