Heatmap

API Response Time Matrix

Seamless heatmap showing API endpoint response times across different hours

Output
API Response Time Matrix
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

fig, ax = plt.subplots(figsize=(12, 8), facecolor='#ffffff')
ax.set_facecolor('#ffffff')

np.random.seed(42)
endpoints = ['GET /users', 'POST /auth', 'GET /products', 'PUT /orders', 'DELETE /cart', 'GET /search']
hours = [f'{h:02d}:00' for h in range(0, 24, 2)]
data = np.random.exponential(50, (len(endpoints), len(hours))) + np.random.rand(len(endpoints), len(hours)) * 100

# Modern gradient: Mint to Teal to Deep Sea
colors = ['#d1fae5', '#6ee7b7', '#14b8a6', '#0f766e', '#134e4a']
cmap = LinearSegmentedColormap.from_list('modern', colors, N=256)

im = ax.imshow(data, cmap=cmap, aspect='auto')

ax.set_xticks(range(len(hours)))
ax.set_yticks(range(len(endpoints)))
ax.set_xticklabels(hours, rotation=45, ha='right', color='#374151', fontsize=9)
ax.set_yticklabels(endpoints, color='#1f2937', fontsize=10, fontweight='500')

for i in range(len(endpoints)):
    for j in range(len(hours)):
        val = data[i, j]
        color = '#ffffff' if val > 100 else '#1f2937'
        ax.text(j, i, f'{val:.0f}', ha='center', va='center', color=color, fontsize=8, fontweight='500')

cbar = plt.colorbar(im, ax=ax, shrink=0.8, pad=0.02)
cbar.set_label('Response Time (ms)', color='#1f2937', fontsize=11)
cbar.outline.set_edgecolor('#e5e7eb')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#6b7280')

for spine in ax.spines.values():
    spine.set_color('#e5e7eb')
ax.set_xlabel('Hour of Day', fontsize=11, color='#374151', fontweight='500')
ax.set_ylabel('Endpoint', fontsize=11, color='#374151', fontweight='500')
ax.set_title('API Response Time by Endpoint & Hour', fontsize=16, color='#111827', fontweight='bold', pad=15)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Heatmaps & Density

Did this help you?

Support PyLucid to keep it free & growing

Support