KDE Plot
API Response Latency KDE
Density distribution of API response times across different endpoints
Output
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
np.random.seed(456)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
# Response times in ms
auth_api = np.random.lognormal(3.5, 0.5, 800)
data_api = np.random.lognormal(4.0, 0.6, 800)
search_api = np.random.lognormal(4.5, 0.7, 800)
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
x_range = np.linspace(0, 400, 500)
for data, color, label in [(auth_api, '#F5276C', 'Auth API'),
(data_api, '#27D3F5', 'Data API'),
(search_api, '#F5B027', 'Search API')]:
data_clipped = data[data < 400]
kde = gaussian_kde(data_clipped)
density = kde(x_range)
ax.plot(x_range, density, color=color, linewidth=2.5, label=label)
ax.fill_between(x_range, density, alpha=0.3, color=color)
ax.axvline(200, color='#ef4444', linestyle='--', alpha=0.8, linewidth=2, label='SLA: 200ms')
ax.set_xlabel('Response Time (ms)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('API Response Latency Distribution', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.set_xlim(0, 400)
ax.tick_params(colors='#888888', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#333333')
ax.legend(facecolor=BG_COLOR, edgecolor='#333333', labelcolor=TEXT_COLOR, fontsize=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕