Stackplot
Sessions by Source
Traffic acquisition channels.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'organic': '#10B981',
'direct': '#6366F1',
'referral': '#F59E0B',
'social': '#EC4899',
'email': '#3B82F6',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9'
}
weeks = np.arange(1, 13)
organic = [3200, 3400, 3600, 3800, 4000, 4200, 4400, 4600, 4800, 5000, 5200, 5400]
direct = [2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100]
referral = [800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900]
social = [600, 700, 850, 1000, 1200, 1400, 1600, 1800, 2000, 2200, 2400, 2600]
email = [400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950]
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
ax.stackplot(weeks, organic, direct, referral, social, email,
colors=[COLORS['organic'], COLORS['direct'], COLORS['referral'], COLORS['social'], COLORS['email']],
alpha=0.85, labels=['Organic', 'Direct', 'Referral', 'Social', 'Email'])
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(1, 12)
ax.set_xlabel('Week', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Sessions', 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
More Stackplot examples
☕