KDE Plot

Restaurant Wait Time Distribution

KDE of wait times at restaurants during peak hours.

Output
Restaurant Wait Time Distribution
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(112)

wait = np.random.exponential(15, 1500)
wait = wait[wait < 60]

kde = stats.gaussian_kde(wait)
x = np.linspace(0, 60, 500)
y = kde(x)

fig, ax = plt.subplots(figsize=(12, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

ax.fill_between(x, y, alpha=0.4, color='#F5276C')
ax.plot(x, y, color='#F5276C', linewidth=3)

ax.axvspan(0, 10, alpha=0.15, color='#6CF527', label='Quick (0-10 min)')
ax.axvspan(10, 20, alpha=0.1, color='#27D3F5', label='Reasonable (10-20 min)')
ax.axvspan(20, 60, alpha=0.1, color='#F5B027', label='Long (20+ min)')

mean_wait = np.mean(wait)
ax.axvline(mean_wait, color='#374151', linestyle='--', linewidth=2)
ax.text(mean_wait+1, max(y)*0.8, 'Avg: ' + str(round(mean_wait, 0)) + ' min', color='#374151', fontsize=10, fontweight='bold')

ax.set_xlabel('Wait Time (minutes)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Restaurant Wait Time 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.legend(loc='upper right', facecolor='#f9fafb', edgecolor='#d1d5db', labelcolor='#374151')
ax.grid(True, alpha=0.3, color='#e5e7eb')
ax.set_xlim(0, 60)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support