Stream Graph

Website Traffic Sources Stream

Stream visualization of website traffic sources over a year showing organic, paid, social, and referral channels.

Output
Website Traffic Sources Stream
Python
import matplotlib.pyplot as plt
import numpy as np

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

np.random.seed(123)
months = np.arange(0, 12)
month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

# Traffic sources
organic = 40 + 15 * np.sin(months * np.pi / 6) + np.random.normal(0, 3, 12)
paid = 25 + 10 * np.cos(months * np.pi / 4) + np.random.normal(0, 2, 12)
social = 20 + 8 * np.sin(months * np.pi / 3 + 1) + np.random.normal(0, 2, 12)
referral = 10 + 5 * np.sin(months * np.pi / 5) + np.random.normal(0, 1, 12)
direct = 15 + 3 * np.cos(months * np.pi / 6) + np.random.normal(0, 1, 12)

data = [organic, paid, social, referral, direct]

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=['Organic', 'Paid', 'Social', 'Referral', 'Direct'])

ax.axhline(0, color=COLORS['grid'], linewidth=0.5)
ax.set_xlim(0, 11)
ax.set_xticks(months)
ax.set_xticklabels(month_names)

ax.set_title('Website Traffic Sources (Annual)', color=COLORS['text'], fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Month', color=COLORS['text'], fontsize=11)
ax.set_ylabel('Traffic (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

Did this help you?

Support PyLucid to keep it free & growing

Support