Mirror Chart
Electric vs Gas Vehicle Range
Mirror histogram comparing driving range with charging/refueling annotations
Output
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
np.random.seed(1974)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
electric = np.random.normal(280, 60, 600)
gas = np.random.normal(420, 80, 800)
electric = electric[(electric > 100) & (electric < 450)]
gas = gas[(gas > 200) & (gas < 650)]
fig, ax = plt.subplots(figsize=(12, 7), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
x = np.linspace(100, 650, 400)
kde_e = gaussian_kde(electric)
y_e = kde_e(x)
ax.fill_between(x, y_e, alpha=0.3, color='#6CF527')
ax.plot(x, y_e, color='#6CF527', linewidth=4, alpha=0.3)
ax.plot(x, y_e, color='#6CF527', linewidth=2, label='Electric Vehicles')
kde_g = gaussian_kde(gas)
y_g = kde_g(x) * -1
ax.fill_between(x, y_g, alpha=0.3, color='#F54927')
ax.plot(x, y_g, color='#F54927', linewidth=4, alpha=0.3)
ax.plot(x, y_g, color='#F54927', linewidth=2, label='Gas Vehicles')
ax.axhline(0, color='#333', linewidth=1.5)
med_e = np.median(electric)
med_g = np.median(gas)
ax.axvline(med_e, color='#6CF527', linestyle='--', linewidth=1.5, alpha=0.7)
ax.axvline(med_g, color='#F54927', linestyle='--', linewidth=1.5, alpha=0.7)
range_gap = med_g - med_e
pct_gap = range_gap / med_e * 100
stats_text = 'Range Comparison:\nElectric: %.0f mi median\nGas: %.0f mi median\nGap: %.0f mi' % (med_e, med_g, range_gap)
ax.text(0.02, 0.98, stats_text.replace('\n', chr(10)), transform=ax.transAxes, fontsize=10,
color=TEXT_COLOR, verticalalignment='top', fontfamily='monospace',
bbox=dict(boxstyle='round,pad=0.5', facecolor='#1a1a2e', edgecolor='#333', alpha=0.9))
ax.annotate('', xy=(med_g, 0.002), xytext=(med_e, 0.002),
arrowprops=dict(arrowstyle='<->', color='#F5B027', lw=2))
ax.text((med_e + med_g)/2, 0.003, '%.0f mi gap' % range_gap,
color='#F5B027', fontsize=10, ha='center', fontweight='bold')
ax.set_xlabel('Range (miles)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Vehicle Range: Electric vs Gas', fontsize=14,
color=TEXT_COLOR, fontweight='bold', pad=15)
ax.tick_params(colors='#888', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#333')
ax.legend(loc='upper right', facecolor='#1a1a2e', edgecolor='#333',
labelcolor=TEXT_COLOR, fontsize=10)
ax.set_xlim(100, 650)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕