Stackplot
Calorie Intake
Daily macronutrient breakdown.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'carbs': '#F59E0B',
'protein': '#EF4444',
'fat': '#10B981',
'fiber': '#6366F1',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9'
}
days = np.arange(1, 8)
day_labels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
carbs = [220, 200, 180, 210, 190, 250, 240]
protein = [80, 90, 100, 85, 95, 70, 75]
fat = [60, 65, 55, 70, 60, 80, 85]
fiber = [25, 30, 35, 28, 32, 20, 22]
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
ax.stackplot(days, carbs, protein, fat, fiber,
colors=[COLORS['carbs'], COLORS['protein'], COLORS['fat'], COLORS['fiber']],
alpha=0.85, labels=['Carbs', 'Protein', 'Fat', 'Fiber'])
ax.axhline(2000/4.5, color=COLORS['text'], linewidth=1, linestyle='--', alpha=0.5)
ax.text(7.2, 2000/4.5, 'Target', fontsize=9, color=COLORS['text_muted'], va='center')
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_xticks(days)
ax.set_xticklabels(day_labels)
ax.set_xlim(1, 7)
ax.set_ylabel('Grams', 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
☕