Stream Graph
Urban Transportation Mode Stream
Stream graph showing urban transportation mode preferences throughout the day.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'layers': ['#EF4444', '#3B82F6', '#10B981', '#F59E0B', '#8B5CF6'],
'background': '#ffffff',
'text': '#1f2937',
'grid': '#e5e7eb',
}
np.random.seed(3838)
hours = np.arange(0, 24)
car = 30 + 20 * np.exp(-((hours - 8)**2) / 8) + 18 * np.exp(-((hours - 17)**2) / 8) + np.random.normal(0, 2, 24)
public_transit = 15 + 25 * np.exp(-((hours - 8)**2) / 6) + 22 * np.exp(-((hours - 18)**2) / 6) + np.random.normal(0, 2, 24)
bike = 8 + 12 * np.exp(-((hours - 8)**2) / 10) + 10 * np.exp(-((hours - 17)**2) / 10) + np.random.normal(0, 1, 24)
rideshare = 5 + 8 * np.exp(-((hours - 22)**2) / 15) + 5 * np.exp(-((hours - 8)**2) / 10) + np.random.normal(0, 1, 24)
walk = 10 + 8 * np.exp(-((hours - 12)**2) / 15) + np.random.normal(0, 1, 24)
data = [np.clip(d, 1, None) for d in [car, public_transit, bike, rideshare, walk]]
fig, ax = plt.subplots(figsize=(14, 6), facecolor=COLORS['background'])
ax.set_facecolor(COLORS['background'])
ax.stackplot(hours, *data, colors=COLORS['layers'], alpha=0.85, baseline='sym',
labels=['Private Car', 'Public Transit', 'Bicycle', 'Rideshare', 'Walking'])
ax.axhline(0, color=COLORS['grid'], linewidth=0.5)
ax.set_xlim(0, 23)
ax.set_xticks([0, 6, 12, 18, 24])
ax.set_xticklabels(['12 AM', '6 AM', '12 PM', '6 PM', '12 AM'])
ax.set_title('Urban Transportation by Hour', color=COLORS['text'], fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Hour', color=COLORS['text'], fontsize=11)
ax.set_ylabel('Trips (thousands)', color=COLORS['text'], fontsize=11)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -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
☕