KDE Plot
Daily Coffee Consumption Distribution
KDE showing daily coffee intake patterns.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(105)
coffee = np.random.gamma(3, 0.8, 1000)
coffee = coffee[coffee < 8]
kde = stats.gaussian_kde(coffee)
x = np.linspace(0, 8, 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='#F5B027')
ax.plot(x, y, color='#F5B027', linewidth=3)
ax.axvspan(0, 2, alpha=0.1, color='#6CF527', label='Light (0-2)')
ax.axvspan(2, 4, alpha=0.1, color='#27D3F5', label='Moderate (2-4)')
ax.axvspan(4, 8, alpha=0.1, color='#F5276C', label='Heavy (4+)')
ax.axvline(4, color='#F5276C', linestyle='--', linewidth=2, alpha=0.7)
ax.text(4.1, max(y)*0.85, 'FDA Limit', color='#F5276C', fontsize=10, fontweight='bold')
ax.set_xlabel('Cups per Day', fontsize=12, color='#1f2937', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Daily Coffee Consumption 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, 8)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕