Stackplot
Percentage Stackplot
100% stacked showing proportions.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'layers': ['#3B82F6', '#10B981', '#F59E0B', '#EF4444'],
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9'
}
months = np.arange(12)
month_labels = ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D']
# Raw data
chrome = [65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54]
safari = [18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
firefox = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
other = [7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]
# Convert to percentages
data = np.array([chrome, safari, firefox, other])
data_pct = data / data.sum(axis=0) * 100
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
ax.stackplot(months, data_pct, colors=COLORS['layers'], alpha=0.85,
labels=['Chrome', 'Safari', 'Firefox', 'Other'])
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(month_labels)
ax.set_xlim(0, 11)
ax.set_ylim(0, 100)
ax.set_ylabel('Market Share (%)', fontsize=10, color=COLORS['text'], labelpad=10)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12), ncol=4, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Stackplot examples
☕