Stream Graph

Electric Vehicle Adoption Stream

Stream graph showing EV adoption rates by manufacturer with legend positioned outside plot.

Output
Electric Vehicle Adoption Stream
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'layers': ['#E31937', '#0066B1', '#CC0000', '#000000', '#00A3E0'],
    'background': '#ffffff',
    'text': '#1f2937',
    'grid': '#e5e7eb',
}

np.random.seed(1111)
years = np.arange(2015, 2025)
n = len(years)

# EV manufacturers
tesla = 10 + 15 * (years - 2015) + np.random.normal(0, 3, n)
byd = 5 + 12 * (years - 2018) * (years >= 2018) + np.random.normal(0, 2, n)
vw = 2 + 8 * (years - 2020) * (years >= 2020) + np.random.normal(0, 1, n)
gm = 3 + 5 * (years - 2019) * (years >= 2019) + np.random.normal(0, 1, n)
hyundai = 2 + 6 * (years - 2019) * (years >= 2019) + np.random.normal(0, 1, n)

data = [np.clip(d, 0.5, None) for d in [tesla, byd, vw, gm, hyundai]]

fig, ax = plt.subplots(figsize=(14, 6), facecolor=COLORS['background'])
ax.set_facecolor(COLORS['background'])

ax.stackplot(years, *data, colors=COLORS['layers'], alpha=0.85, baseline='sym',
             labels=['Tesla', 'BYD', 'VW Group', 'GM', 'Hyundai/Kia'])

ax.axhline(0, color=COLORS['grid'], linewidth=0.5)
ax.set_xlim(2015, 2024)

ax.set_title('Electric Vehicle Sales by Manufacturer', color=COLORS['text'], fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Year', color=COLORS['text'], fontsize=11)
ax.set_ylabel('Sales (Millions)', color=COLORS['text'], fontsize=11)

# Legend outside plot area
ax.legend(loc='upper left', bbox_to_anchor=(0, -0.12), frameon=False, fontsize=9, ncol=5)

for spine in ax.spines.values():
    spine.set_color(COLORS['grid'])
ax.tick_params(colors=COLORS['text'], labelsize=9)

plt.tight_layout()
plt.subplots_adjust(bottom=0.18)
plt.show()
Library

Matplotlib

Category

Time Series

Did this help you?

Support PyLucid to keep it free & growing

Support