Stairs Plot
Stock Price Steps
Daily closing prices as steps.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'line': '#6366F1',
'up': '#10B981',
'down': '#EF4444',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9'
}
np.random.seed(42)
prices = 100 + np.cumsum(np.random.randn(31) * 2)
edges = np.arange(32)
fig, ax = plt.subplots(figsize=(12, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# Clean line
ax.stairs(prices, edges, linewidth=2.5, color=COLORS['line'])
# Color points by direction
for i in range(len(prices)):
color = COLORS['up'] if i == 0 or prices[i] >= prices[i-1] else COLORS['down']
ax.scatter(i + 0.5, prices[i], s=40, c=color, edgecolors='white', linewidths=1.5, zorder=4)
# Current price
final_change = prices[-1] - prices[0]
color = COLORS['up'] if final_change >= 0 else COLORS['down']
ax.annotate(f'${prices[-1]:.2f} ({final_change:+.2f})', (31, prices[-1]),
xytext=(5, 0), textcoords='offset points', fontsize=10,
fontweight='bold', color=color, va='center')
ax.axhline(100, color=COLORS['text_muted'], linewidth=1, linestyle=':', alpha=0.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, 34)
ax.set_xlabel('Day', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Price ($)', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Stairs Plot examples
☕