Stairs Plot
CPU Usage Steps
System monitoring step chart.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'cpu': '#EF4444',
'warning': '#F59E0B',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9'
}
np.random.seed(42)
samples = 40
cpu = np.clip(45 + 35*np.sin(np.arange(samples)/6) + np.random.normal(0, 8, samples), 0, 100)
edges = np.arange(samples + 1)
fig, ax = plt.subplots(figsize=(12, 5), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
ax.stairs(cpu, edges, fill=True, alpha=0.2, facecolor=COLORS['cpu'], linewidth=0)
ax.stairs(cpu, edges, linewidth=2, color=COLORS['cpu'])
# Thresholds
ax.axhline(80, color=COLORS['cpu'], linewidth=1.5, linestyle='--', alpha=0.7)
ax.axhline(60, color=COLORS['warning'], linewidth=1.5, linestyle='--', alpha=0.7)
ax.text(41, 80, 'Critical', fontsize=9, color=COLORS['cpu'], va='center')
ax.text(41, 60, 'Warning', fontsize=9, color=COLORS['warning'], va='center')
# Current
ax.scatter([samples - 0.5], [cpu[-1]], s=80, c=COLORS['cpu'], edgecolors='white', linewidths=2, zorder=5)
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, 44)
ax.set_ylim(0, 100)
ax.set_xlabel('Sample', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('CPU (%)', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Stairs Plot examples
☕