Stackplot

Transportation Mix

City transport mode share.

Output
Transportation Mix
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'car': '#64748B',
    'bus': '#10B981',
    'metro': '#3B82F6',
    'bike': '#F59E0B',
    'walk': '#EC4899',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9'
}

years = np.arange(2010, 2025)
car = [60, 58, 55, 52, 50, 48, 45, 42, 40, 38, 35, 32, 30, 28, 26]
bus = [15, 15, 16, 16, 17, 17, 18, 18, 18, 18, 18, 18, 18, 17, 17]
metro = [10, 11, 12, 14, 15, 17, 18, 20, 22, 24, 26, 28, 30, 32, 33]
bike = [5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 13, 14, 14, 15, 16]
walk = [10, 10, 10, 10, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8]

fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

ax.stackplot(years, car, bus, metro, bike, walk,
             colors=[COLORS['car'], COLORS['bus'], COLORS['metro'], COLORS['bike'], COLORS['walk']],
             alpha=0.85, labels=['Car', 'Bus', 'Metro', 'Bike', 'Walk'])

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_color(COLORS['grid'])
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.set_xlim(2010, 2024)
ax.set_ylim(0, 100)
ax.set_ylabel('Mode Share (%)', fontsize=10, color=COLORS['text'], labelpad=10)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12), ncol=5, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support