Error Bar Chart

Electric Vehicle Range Comparison

EV range comparison between EPA ratings and real-world driving conditions.

Output
Electric Vehicle Range Comparison
Python
import matplotlib.pyplot as plt
import numpy as np

np.random.seed(42)

# EV range data
vehicles = ['Tesla\nModel 3', 'BMW\niX', 'Mercedes\nEQS', 'Rivian\nR1T', 'Ford\nMustang']
epa_range = np.array([358, 324, 350, 314, 312])
real_range = np.array([310, 285, 320, 275, 280])
epa_err = np.array([15, 12, 18, 14, 10])
real_err = np.array([25, 22, 28, 24, 20])

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

x = np.arange(len(vehicles))
width = 0.35

bars1 = ax.bar(x - width/2, epa_range, width, yerr=epa_err, label='EPA Rated',
               color='#6CF527', edgecolor='#1f2937', capsize=4,
               error_kw={'ecolor': '#374151', 'elinewidth': 1.5})
bars2 = ax.bar(x + width/2, real_range, width, yerr=real_err, label='Real-World',
               color='#F5B027', edgecolor='#1f2937', capsize=4,
               error_kw={'ecolor': '#374151', 'elinewidth': 1.5})

ax.set_xlabel('Vehicle', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Range (miles)', fontsize=11, color='#374151', fontweight='500')
ax.set_title('Electric Vehicle Range: EPA vs Real-World', fontsize=14, 
             color='#1f2937', fontweight='bold', pad=15)

ax.set_xticks(x)
ax.set_xticklabels(vehicles)
ax.legend(facecolor='#f8fafc', edgecolor='#d1d5db', fontsize=10)
ax.tick_params(colors='#6b7280', labelsize=9)
ax.set_ylim(200, 420)
ax.grid(True, axis='y', alpha=0.3, color='#d1d5db')
for spine in ax.spines.values():
    spine.set_color('#d1d5db')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support