Heatmap

Response Time Heatmap

Dark theme heatmap showing API response times by endpoint

Output
Response Time Heatmap
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
from matplotlib.patches import FancyBboxPatch

fig, ax = plt.subplots(figsize=(14, 7), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

np.random.seed(42)
endpoints = ['/api/users', '/api/orders', '/api/products', '/api/auth', '/api/search']
hours = [f'{h:02d}:00' for h in range(0, 24, 2)]
data = np.random.gamma(2, 50, (len(endpoints), len(hours)))

colors = ['#1e293b', '#065f46', '#22c55e', '#facc15', '#ef4444']
cmap = LinearSegmentedColormap.from_list('latency', colors, N=256)

cell_w, cell_h = 0.88, 0.82
for i in range(len(endpoints)):
    for j in range(len(hours)):
        val = data[i, j]
        rect = FancyBboxPatch((j - cell_w/2, i - cell_h/2), cell_w, cell_h,
                               boxstyle="round,pad=0.02,rounding_size=0.12",
                               facecolor=cmap(val/data.max()), edgecolor='#e2e8f0', linewidth=1.5)
        ax.add_patch(rect)

ax.set_xlim(-0.5, len(hours)-0.5)
ax.set_ylim(-0.5, len(endpoints)-0.5)
ax.set_aspect('equal')
ax.invert_yaxis()
ax.set_xticks(range(len(hours)))
ax.set_yticks(range(len(endpoints)))
ax.set_xticklabels(hours, rotation=45, ha='right', color='#64748b', fontsize=9, fontweight='500')
ax.set_yticklabels(endpoints, color='#1e293b', fontsize=9, fontweight='500', family='monospace')

sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(0, data.max()))
cbar = plt.colorbar(sm, ax=ax, shrink=0.8, pad=0.02)
cbar.set_label('Response Time (ms)', color='#1e293b', fontsize=11)
cbar.outline.set_edgecolor('#e2e8f0')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#64748b')

for spine in ax.spines.values(): spine.set_visible(False)
ax.tick_params(length=0)
ax.set_title('API Response Time by Endpoint', fontsize=18, color='#1e293b', fontweight='bold', pad=20)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Heatmaps & Density

Did this help you?

Support PyLucid to keep it free & growing

Support