KDE Plot
Engine Operating Temperature
KDE of vehicle engine temperatures during operation.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(208)
cold_start = np.random.normal(40, 15, 200)
normal = np.random.normal(90, 10, 600)
hot = np.random.normal(105, 8, 200)
temps = np.concatenate([cold_start, normal, hot])
temps = temps[(temps > 20) & (temps < 130)]
kde = stats.gaussian_kde(temps)
x = np.linspace(20, 130, 500)
y = kde(x)
colors = ['#1e3a8a', '#3b82f6', '#22d3ee', '#fbbf24', '#f97316', '#dc2626']
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')
for i in range(len(x)-1):
norm_val = (x[i] - 20) / 110
color_idx = int(norm_val * (len(colors) - 1))
color_idx = max(0, min(color_idx, len(colors)-1))
ax.fill_between(x[i:i+2], y[i:i+2], alpha=0.6, color=colors[color_idx])
ax.plot(x, y, color='#374151', linewidth=2.5)
ax.axvspan(85, 100, alpha=0.15, color='#22d3ee', label='Optimal (85-100C)')
ax.axvline(50, color='#3b82f6', linestyle='--', linewidth=1.5, alpha=0.7)
ax.text(52, max(y)*0.9, 'Cold', color='#3b82f6', fontsize=9, fontweight='bold')
ax.axvline(110, color='#dc2626', linestyle='--', linewidth=2, label='Overheating (>110C)')
ax.set_xlabel('Engine Temperature (C)', fontsize=12, color='#1f2937', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='#1f2937', fontweight='500')
ax.set_title('Engine Operating Temperature 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(20, 130)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕