Stairs Plot

Power Consumption

Hourly energy usage.

Output
Power Consumption
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {'power': '#F59E0B', 'background': '#FFFFFF', 'text': '#1E293B', 'text_muted': '#64748B', 'grid': '#F1F5F9'}

hours = np.arange(24)
power = [3.2, 2.8, 2.5, 2.3, 2.2, 2.5, 4.0, 6.5, 7.2, 6.8, 6.5, 7.0, 7.5, 7.2, 6.8, 6.5, 7.0, 8.5, 8.0, 7.0, 5.5, 4.5, 4.0, 3.5]
edges = np.arange(25)

fig, ax = plt.subplots(figsize=(12, 5), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

ax.stairs(power, edges, fill=True, alpha=0.25, facecolor=COLORS['power'])
ax.stairs(power, edges, linewidth=2.5, color=COLORS['power'])

# Average
avg = np.mean(power)
ax.axhline(avg, color=COLORS['power'], linewidth=1.5, linestyle='--', alpha=0.7)
ax.text(24.3, avg, f'Avg: {avg:.1f}kW', fontsize=9, color=COLORS['power'], 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_xlim(0, 24)
ax.set_ylim(0, 10)
ax.set_xticks([0, 6, 12, 18, 24])
ax.set_xticklabels(['12AM', '6AM', '12PM', '6PM', '12AM'])
ax.set_ylabel('Power (kW)', fontsize=10, color=COLORS['text'], labelpad=10)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support