Stackplot

E-commerce Orders

Order volume by product category.

Output
E-commerce Orders
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'electronics': '#3B82F6',
    'clothing': '#EC4899',
    'home': '#10B981',
    'beauty': '#F59E0B',
    'food': '#EF4444',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9'
}

months = np.arange(1, 13)
electronics = [1200, 1100, 1300, 1150, 1400, 1350, 1500, 1600, 1800, 2500, 3500, 2800]
clothing = [800, 750, 900, 1100, 1000, 850, 700, 800, 1200, 1400, 1800, 1500]
home = [600, 650, 700, 750, 800, 850, 900, 950, 1000, 1200, 1500, 1300]
beauty = [400, 420, 450, 500, 520, 550, 580, 600, 650, 800, 1000, 850]
food = [300, 320, 350, 380, 400, 450, 480, 500, 550, 700, 900, 750]

fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

ax.stackplot(months, electronics, clothing, home, beauty, food,
             colors=[COLORS['electronics'], COLORS['clothing'], COLORS['home'], COLORS['beauty'], COLORS['food']],
             alpha=0.85, labels=['Electronics', 'Clothing', 'Home', 'Beauty', 'Food'])

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_xticks(months)
ax.set_xticklabels(['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'])
ax.set_xlim(1, 12)
ax.set_ylabel('Orders', 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

Did this help you?

Support PyLucid to keep it free & growing

Support