Stackplot
Learning Hours
Study time by subject area.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'math': '#6366F1',
'science': '#10B981',
'language': '#F59E0B',
'arts': '#EC4899',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9'
}
weeks = np.arange(1, 17)
math = [5, 4, 6, 5, 7, 6, 8, 7, 6, 8, 9, 8, 10, 9, 11, 12]
science = [4, 5, 4, 6, 5, 7, 6, 8, 7, 6, 7, 8, 8, 9, 9, 10]
language = [3, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7, 7]
arts = [2, 2, 2, 3, 2, 3, 3, 3, 4, 3, 4, 4, 4, 5, 5, 5]
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
ax.stackplot(weeks, math, science, language, arts,
colors=[COLORS['math'], COLORS['science'], COLORS['language'], COLORS['arts']],
alpha=0.85, labels=['Mathematics', 'Science', 'Language', 'Arts'])
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.yaxis.grid(True, color=COLORS['grid'], linewidth=1, zorder=0)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.set_xlim(1, 16)
ax.set_xlabel('Week', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Hours', 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
☕