Stream Graph

Online Learning Platform Usage Stream

Stream graph showing online course enrollment across different subject areas.

Output
Online Learning Platform Usage Stream
Python
import matplotlib.pyplot as plt
import numpy as np

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

np.random.seed(3232)
months = np.arange(0, 36)

programming = 30 + 1.5 * months + 5 * np.sin(months * np.pi / 6) + np.random.normal(0, 2, 36)
data_science = 20 + 2 * months + np.random.normal(0, 2, 36)
business = 25 + 0.5 * months + 3 * np.cos(months * np.pi / 8) + np.random.normal(0, 2, 36)
design = 15 + 0.8 * months + np.random.normal(0, 1, 36)
languages = 18 + 0.3 * months + np.random.normal(0, 1, 36)
marketing = 12 + 0.6 * months + np.random.normal(0, 1, 36)

data = [np.clip(d, 1, None) for d in [programming, data_science, business, design, languages, marketing]]

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=['Programming', 'Data Science', 'Business', 'Design', 'Languages', 'Marketing'])

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

ax.set_title('Online Course Enrollment by Subject', color=COLORS['text'], fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Month', color=COLORS['text'], fontsize=11)
ax.set_ylabel('Students (thousands)', color=COLORS['text'], fontsize=11)

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

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