Stairs Plot

API Response Time

Service latency monitoring.

Output
API Response Time
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {'latency': '#8B5CF6', 'good': '#10B981', 'slow': '#EF4444', 'background': '#FFFFFF', 'text': '#1E293B', 'text_muted': '#64748B', 'grid': '#F1F5F9'}

np.random.seed(42)
samples = 25
latency = np.clip(50 + 30*np.sin(np.arange(samples)/4) + np.random.normal(0, 15, samples), 10, 150)
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(latency, edges, fill=True, alpha=0.2, facecolor=COLORS['latency'])
ax.stairs(latency, edges, linewidth=2, color=COLORS['latency'])

# Thresholds
ax.axhline(100, color=COLORS['slow'], linewidth=1.5, linestyle='--', alpha=0.7)
ax.axhline(50, color=COLORS['good'], linewidth=1.5, linestyle='--', alpha=0.7)

p95 = np.percentile(latency, 95)
ax.axhline(p95, color=COLORS['latency'], linewidth=1.5, linestyle=':')
ax.text(25.5, p95, f'p95: {p95:.0f}ms', fontsize=9, color=COLORS['latency'], 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, 25)
ax.set_ylim(0, 130)
ax.set_xlabel('Sample', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Latency (ms)', 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