Stairs Plot

Active Sessions

Concurrent user sessions.

Output
Active Sessions
Python
import matplotlib.pyplot as plt
import numpy as np

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

hours = np.arange(24)
sessions = [120, 80, 50, 30, 25, 40, 150, 350, 520, 580, 620, 650, 680, 640, 600, 580, 620, 700, 650, 550, 420, 320, 220, 160]
edges = np.arange(25)

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

ax.stairs(sessions, edges, fill=True, alpha=0.25, facecolor=COLORS['sessions'])
ax.stairs(sessions, edges, linewidth=2.5, color=COLORS['sessions'])

# Peak hour
peak_idx = np.argmax(sessions)
ax.scatter([peak_idx + 0.5], [sessions[peak_idx]], s=60, c=COLORS['sessions'], edgecolors='white', linewidths=2, zorder=4)
ax.annotate(f'Peak: {sessions[peak_idx]}', (peak_idx + 0.5, sessions[peak_idx]),
            xytext=(5, 8), textcoords='offset points', fontsize=9, color=COLORS['sessions'], fontweight='bold')

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, 24)
ax.set_ylim(0, 750)
ax.set_xticks([0, 6, 12, 18, 24])
ax.set_xticklabels(['12AM', '6AM', '12PM', '6PM', '12AM'])
ax.set_ylabel('Sessions', 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