Stairs Plot

Memory Pressure

Application memory usage.

Output
Memory Pressure
Python
import matplotlib.pyplot as plt
import numpy as np

COLORS = {'memory': '#EC4899', 'background': '#FFFFFF', 'text': '#1E293B', 'text_muted': '#64748B', 'grid': '#F1F5F9'}

np.random.seed(42)
time = 20
memory = [2.0, 2.2, 2.5, 2.8, 3.2, 3.5, 4.0, 4.5, 4.8, 5.2, 2.0, 2.3, 2.8, 3.2, 3.8, 4.2, 4.8, 5.5, 6.0, 6.5]
edges = np.arange(len(memory) + 1)

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

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

# GC event
ax.annotate('GC', (10, 2.0), xytext=(0, -20), textcoords='offset points',
            fontsize=9, color=COLORS['memory'], fontweight='bold', ha='center',
            arrowprops=dict(arrowstyle='->', color=COLORS['memory'], lw=1.5))

# Limit line
ax.axhline(8, color='#EF4444', linewidth=1.5, linestyle='--', alpha=0.7)
ax.text(20.3, 8, 'Limit', fontsize=9, color='#EF4444', 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, 20)
ax.set_ylim(0, 9)
ax.set_xlabel('Time (min)', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Memory (GB)', 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