KDE Plot

Indoor Humidity Distribution

KDE of indoor humidity levels with comfort zones.

Output
Indoor Humidity Distribution
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(119)

humidity = np.random.normal(50, 15, 1000)
humidity = humidity[(humidity > 10) & (humidity < 90)]

kde = stats.gaussian_kde(humidity)
x = np.linspace(10, 90, 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='#D3F527')
ax.plot(x, y, color='#D3F527', linewidth=3)

ax.axvspan(30, 50, alpha=0.2, color='#6CF527', label='Optimal (30-50%)')
ax.axvspan(10, 30, alpha=0.1, color='#F54927', label='Too Dry')
ax.axvspan(50, 60, alpha=0.1, color='#27D3F5', label='Acceptable')
ax.axvspan(60, 90, alpha=0.1, color='#F5276C', label='Too Humid')

ax.set_xlabel('Relative Humidity (%)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Indoor Humidity 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(10, 90)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support