Hexbin Plot

Network Latency Heatmap

Hexbin showing request latency vs payload size distribution

Output
Network Latency Heatmap
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(111)
payload_size = np.random.lognormal(5, 1.5, 7000)
latency = 10 + 0.001 * payload_size + np.random.exponential(20, 7000)

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

colors = ['#0f172a', '#1e3a5f', '#2563eb', '#3b82f6', '#60a5fa', '#93c5fd', '#bfdbfe', '#dbeafe']
cmap = LinearSegmentedColormap.from_list('blue_glow', colors, N=256)

hb = ax.hexbin(payload_size/1000, latency, gridsize=30, cmap=cmap, mincnt=1, edgecolors='none')

cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.ax.set_facecolor('#0f172a')
cbar.outline.set_edgecolor('#1e3a5f')
cbar.ax.tick_params(colors='#60a5fa', labelsize=9)
cbar.set_label('Request Count', color='#60a5fa', fontsize=10)

ax.set_xlabel('Payload Size (KB)', color='#60a5fa', fontsize=11)
ax.set_ylabel('Latency (ms)', color='#60a5fa', fontsize=11)
ax.tick_params(colors='#60a5fa', labelsize=10)
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support