Stream Graph
Energy Consumption by Sector Stream
Stream graph showing energy consumption patterns across industrial, residential, commercial, and transport sectors.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'layers': ['#EF4444', '#F59E0B', '#10B981', '#3B82F6', '#8B5CF6'],
'background': '#ffffff',
'text': '#1f2937',
'grid': '#e5e7eb',
}
np.random.seed(456)
hours = np.arange(0, 24)
# Energy by sector (hourly pattern)
industrial = 40 + 10 * (1 - np.abs(hours - 14) / 14) + np.random.normal(0, 2, 24)
residential = 20 + 15 * np.exp(-((hours - 19)**2) / 10) + 10 * np.exp(-((hours - 7)**2) / 5) + np.random.normal(0, 2, 24)
commercial = 25 * np.exp(-((hours - 13)**2) / 20) + np.random.normal(0, 2, 24)
transport = 15 + 10 * np.exp(-((hours - 8)**2) / 5) + 8 * np.exp(-((hours - 17)**2) / 5) + np.random.normal(0, 1, 24)
agriculture = 8 + 5 * np.sin(hours * np.pi / 12) + np.random.normal(0, 1, 24)
data = [np.clip(d, 1, None) for d in [industrial, residential, commercial, transport, agriculture]]
fig, ax = plt.subplots(figsize=(14, 6), facecolor=COLORS['background'])
ax.set_facecolor(COLORS['background'])
ax.stackplot(hours, *data, colors=COLORS['layers'], alpha=0.85, baseline='sym',
labels=['Industrial', 'Residential', 'Commercial', 'Transport', 'Agriculture'])
ax.axhline(0, color=COLORS['grid'], linewidth=0.5)
ax.set_xlim(0, 23)
ax.set_xticks([0, 6, 12, 18, 24])
ax.set_xticklabels(['00:00', '06:00', '12:00', '18:00', '24:00'])
ax.set_title('Daily Energy Consumption by Sector', color=COLORS['text'], fontsize=14, fontweight='bold', pad=15)
ax.set_xlabel('Hour of Day', color=COLORS['text'], fontsize=11)
ax.set_ylabel('Energy (GWh)', color=COLORS['text'], fontsize=11)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12), frameon=False, fontsize=9, ncol=5)
for spine in ax.spines.values():
spine.set_color(COLORS['grid'])
ax.tick_params(colors=COLORS['text'], labelsize=9)
plt.tight_layout()
plt.subplots_adjust(bottom=0.18)
plt.show()
Library
Matplotlib
Category
Time Series
More Stream Graph examples
☕