Ridgeline Plot

EV Driving Range by Model

Electric vehicle performance with eco-tech theme

Output
EV Driving Range by Model
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(666)

models = ['Model S', 'Model 3', 'ID.4', 'Ioniq 6', 'EV6', 'Mach-E']
colors = ['#F5276C', '#27D3F5', '#6CF527', '#F5B027', '#4927F5', '#27F5B0']

data = {
    'Model S': np.random.normal(405, 25, 500),
    'Model 3': np.random.normal(358, 30, 500),
    'ID.4': np.random.normal(275, 35, 500),
    'Ioniq 6': np.random.normal(361, 28, 500),
    'EV6': np.random.normal(310, 32, 500),
    'Mach-E': np.random.normal(312, 35, 500)
}

fig, ax = plt.subplots(figsize=(12, 8), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

overlap = 1.6
x_range = np.linspace(150, 500, 300)

for i, (model, range_mi) in enumerate(data.items()):
    kde = stats.gaussian_kde(range_mi, bw_method=0.3)
    y = kde(x_range) * 3.5
    baseline = i * overlap
    
    for w, a in [(12, 0.1), (8, 0.15), (5, 0.3), (2.5, 0.5)]:
        ax.plot(x_range, y + baseline, color=colors[i], linewidth=w, alpha=a)
    
    ax.fill_between(x_range, baseline, y + baseline, alpha=0.5, color=colors[i])
    ax.plot(x_range, y + baseline, color='white', linewidth=1.2, alpha=0.9)
    
    ax.text(145, baseline + 0.12, model, fontsize=10, color=colors[i],
            ha='right', va='bottom', fontweight='600')

ax.set_xlim(100, 500)
ax.set_ylim(-0.3, len(models) * overlap + 1.8)
ax.set_xlabel('Range (miles)', fontsize=12, color='#666666', fontweight='500')
ax.set_title('EV Driving Range by Model', fontsize=16, color='white', fontweight='bold', pad=20)

ax.tick_params(axis='x', colors='#555555', labelsize=10)
ax.tick_params(axis='y', left=False, labelleft=False)
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support