KDE Plot
EV Charging Session Duration KDE
Density distribution of electric vehicle charging session durations
Output
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
np.random.seed(321)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
# Charging duration in minutes
level2_home = np.random.gamma(8, 30, 500)
level2_public = np.random.gamma(5, 20, 500)
dcfc = np.random.gamma(3, 10, 500)
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
x_range = np.linspace(0, 400, 500)
for data, color, label in [(level2_home, '#6CF527', 'Home L2'),
(level2_public, '#27D3F5', 'Public L2'),
(dcfc, '#F5276C', 'DC Fast')]:
data_clipped = data[data < 400]
kde = gaussian_kde(data_clipped)
density = kde(x_range)
ax.plot(x_range, density, color=color, linewidth=2.5, label=label)
ax.fill_between(x_range, density, alpha=0.3, color=color)
ax.set_xlabel('Charging Duration (minutes)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('EV Charging Session Duration Distribution', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.set_xlim(0, 400)
ax.tick_params(colors='#888888', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#333333')
ax.legend(facecolor=BG_COLOR, edgecolor='#333333', labelcolor=TEXT_COLOR, fontsize=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕