Stackplot
Energy Consumption
Daily energy usage by source.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'solar': '#FBBF24',
'wind': '#10B981',
'hydro': '#3B82F6',
'nuclear': '#8B5CF6',
'gas': '#F97316',
'coal': '#64748B',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9'
}
hours = np.arange(24)
solar = [0, 0, 0, 0, 0, 2, 8, 15, 22, 28, 32, 35, 35, 33, 30, 25, 18, 10, 3, 0, 0, 0, 0, 0]
wind = [12, 14, 15, 16, 15, 14, 12, 10, 8, 7, 6, 5, 5, 6, 7, 9, 11, 13, 15, 16, 15, 14, 13, 12]
hydro = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
nuclear = [20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20]
gas = [18, 16, 15, 14, 15, 18, 22, 25, 20, 15, 12, 10, 10, 11, 13, 16, 21, 27, 28, 26, 24, 22, 20, 18]
coal = [15, 15, 15, 15, 15, 16, 18, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 19, 18, 17, 16, 15, 15]
fig, ax = plt.subplots(figsize=(12, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
ax.stackplot(hours, solar, wind, hydro, nuclear, gas, coal,
colors=[COLORS['solar'], COLORS['wind'], COLORS['hydro'],
COLORS['nuclear'], COLORS['gas'], COLORS['coal']],
alpha=0.85, labels=['Solar', 'Wind', 'Hydro', 'Nuclear', 'Gas', 'Coal'])
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(0, 23)
ax.set_xticks([0, 6, 12, 18, 23])
ax.set_xticklabels(['12AM', '6AM', '12PM', '6PM', '11PM'])
ax.set_ylabel('Power (GW)', fontsize=10, color=COLORS['text'], labelpad=10)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.10), ncol=6, frameon=False, fontsize=8, labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Stackplot examples
☕