Boxplot
Electric Vehicle Range
Real-world driving range across EV manufacturers
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
brands = ['Tesla', 'Rivian', 'Lucid', 'Porsche', 'BMW']
data = [
np.random.normal(310, 25, 150),
np.random.normal(280, 30, 150),
np.random.normal(350, 35, 150),
np.random.normal(250, 20, 150),
np.random.normal(270, 28, 150)
]
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor('#0a0a0f')
fig.patch.set_facecolor('#0a0a0f')
colors = ['#C82909', '#6CF527', '#5314E6', '#F5B027', '#27D3F5']
bp = ax.boxplot(data, widths=0.55, patch_artist=True, showfliers=False,
medianprops=dict(color='white', linewidth=2.5))
for patch, color in zip(bp['boxes'], colors):
patch.set_facecolor(color)
patch.set_alpha(0.85)
patch.set_edgecolor(color)
patch.set_linewidth(1.5)
for i, color in enumerate(colors):
bp['whiskers'][i*2].set_color(color)
bp['whiskers'][i*2+1].set_color(color)
bp['caps'][i*2].set_color(color)
bp['caps'][i*2+1].set_color(color)
ax.axhline(300, color='#27F5B0', linewidth=1.5, linestyle=':', alpha=0.6, label='300mi Target')
ax.set_xticklabels(brands)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#333333')
ax.spines['bottom'].set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5, zorder=0)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors='#888888', labelsize=9, length=0, pad=8)
ax.set_ylabel('Range (miles)', fontsize=11, color='white', fontweight='500')
ax.set_title('Electric Vehicle Real-World Range', fontsize=14, color='white', fontweight='bold', pad=15)
ax.legend(loc='lower right', facecolor='#0a0a0f', edgecolor='#333333', labelcolor='white')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕