Stream Graph

Airline Passenger Traffic Stream

Stream graph showing airline passenger distribution by travel class.

Output
Airline Passenger Traffic Stream
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'layers': ['#3B82F6', '#10B981', '#F59E0B', '#8B5CF6'],
    'background': '#ffffff',
    'text': '#1f2937',
    'grid': '#e5e7eb',
}

np.random.seed(2424)
months = np.arange(0, 48)

economy = 70 + 10 * np.sin(months * np.pi / 6) + np.random.normal(0, 3, 48)
premium_eco = 15 + 3 * np.sin(months * np.pi / 6 + 0.5) + np.random.normal(0, 1, 48)
business = 10 + 2 * np.sin(months * np.pi / 6 + 1) + np.random.normal(0, 1, 48)
first_class = 5 + 1 * np.sin(months * np.pi / 6 + 1.5) + np.random.normal(0, 0.5, 48)

data = [np.clip(d, 1, None) for d in [economy, premium_eco, business, first_class]]

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

ax.stackplot(months, *data, colors=COLORS['layers'], alpha=0.85, baseline='sym',
             labels=['Economy', 'Premium Economy', 'Business', 'First Class'])

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

ax.set_title('Airline Passenger Traffic by Class', color=COLORS['text'], fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Month', color=COLORS['text'], fontsize=11)
ax.set_ylabel('Passengers (millions)', color=COLORS['text'], fontsize=11)

ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12), frameon=False, fontsize=9, ncol=4)

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