2D Histogram

API Latency vs Payload Size

2D histogram of API response times versus request payload sizes.

Output
API Latency vs Payload Size
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(42)

# API performance data
payload_size = np.random.exponential(500, 5000)  # KB
latency = 10 + payload_size * 0.05 + np.random.exponential(20, 5000)

fig, ax = plt.subplots(figsize=(10, 8), facecolor='#020B14')
ax.set_facecolor('#020B14')

# Custom colormap: deep_purple to pink
colors = ['#020B14', '#1a0d2e', '#5314E6', '#F527B0']
cmap = LinearSegmentedColormap.from_list('purple_pink', colors, N=256)

h = ax.hist2d(payload_size, latency, bins=50, cmap=cmap, cmin=1)
cbar = plt.colorbar(h[3], ax=ax, pad=0.02)
cbar.set_label('Request Count', color='white', fontsize=11)
cbar.ax.yaxis.set_tick_params(color='white')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='white')

ax.set_xlabel('Payload Size (KB)', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Latency (ms)', fontsize=11, color='white', fontweight='500')
ax.set_title('API Latency vs Payload Size', fontsize=14, color='white', fontweight='bold', pad=15)

ax.tick_params(colors='white', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support