Stairs Plot

Histogram Stairs

Data distribution using stairs.

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

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

np.random.seed(42)
data = np.random.normal(50, 15, 1000)
counts, edges = np.histogram(data, bins=25)

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

# Clean filled stairs
ax.stairs(counts, edges, fill=True, alpha=0.3, facecolor=COLORS['primary'], linewidth=0)
ax.stairs(counts, edges, linewidth=2.5, color=COLORS['primary'])

# Mean line
mean_val = np.mean(data)
ax.axvline(mean_val, color=COLORS['primary'], linewidth=2, linestyle='--', alpha=0.8)
ax.scatter([mean_val], [max(counts) + 5], marker='v', s=80, c=COLORS['primary'], zorder=5)
ax.text(mean_val + 2, max(counts) + 5, f'Mean: {mean_val:.1f}', fontsize=10, 
        fontweight='bold', color=COLORS['primary'], 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_xlabel('Value', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Frequency', 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