Stairs Plot
Battery Level Monitor
Device battery over time.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {'high': '#10B981', 'medium': '#F59E0B', 'low': '#EF4444', 'background': '#FFFFFF', 'text': '#1E293B', 'text_muted': '#64748B', 'grid': '#F1F5F9'}
hours = np.arange(25)
battery = [100, 98, 95, 90, 85, 78, 70, 62, 55, 48, 100, 95, 88, 80, 72, 65, 58, 50, 42, 35, 28, 22, 15, 10, 5]
edges = np.arange(26)
fig, ax = plt.subplots(figsize=(12, 5), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# Color segments by level
for i in range(len(battery)):
color = COLORS['high'] if battery[i] > 50 else COLORS['medium'] if battery[i] > 20 else COLORS['low']
ax.fill_between([i, i+1], 0, battery[i], alpha=0.3, color=color, step='post')
ax.plot([i, i+1], [battery[i], battery[i]], color=color, linewidth=2.5)
if i < len(battery) - 1:
ax.plot([i+1, i+1], [battery[i], battery[i+1]], color=color, linewidth=2.5)
ax.axhline(20, color=COLORS['low'], linewidth=1, linestyle='--', alpha=0.5)
ax.text(25.5, 20, 'Low', fontsize=9, color=COLORS['low'], 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, 105)
ax.set_xlabel('Hour', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Battery (%)', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Stairs Plot examples
☕