Stairs Plot

Baseline Stairs

Steps with custom baseline.

Output
Baseline Stairs
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {
    'primary': '#F59E0B',
    'baseline': '#10B981',
    'background': '#FFFFFF',
    'text': '#1E293B',
    'text_muted': '#64748B',
    'grid': '#F1F5F9'
}

y = [5, 7, 6, 8, 7, 9, 8, 7, 8, 9]
baseline_val = 4
edges = np.arange(len(y) + 1)

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

ax.stairs(y, edges, fill=True, alpha=0.25, facecolor=COLORS['primary'], baseline=baseline_val, linewidth=0)
ax.stairs(y, edges, linewidth=2.5, color=COLORS['primary'], baseline=baseline_val)

# Baseline
ax.axhline(baseline_val, color=COLORS['baseline'], linewidth=2, linestyle='--')
ax.text(10.2, baseline_val, f'Baseline: {baseline_val}', fontsize=10, color=COLORS['baseline'], 
        fontweight='bold', va='center')

# Markers
midpoints = edges[:-1] + 0.5
ax.scatter(midpoints, y, s=50, c=COLORS['primary'], edgecolors='white', linewidths=2, zorder=4)

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, 12)
ax.set_ylim(0, 11)
ax.set_xlabel('Period', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Value', 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