KDE Plot
API Response Time Distribution
KDE showing server response time patterns with performance gradient.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(46)
# Generate response times (log-normal is typical for response times)
response_times = np.random.lognormal(4.5, 0.8, 2000)
response_times = response_times[response_times < 1000]
kde = stats.gaussian_kde(response_times)
x = np.linspace(0, 500, 500)
y = kde(x)
colors = ['#1e3a8a', '#3b82f6', '#22d3ee', '#fbbf24', '#f97316', '#dc2626']
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
# Color based on response time (fast=blue, slow=red)
for i in range(len(x)-1):
time_normalized = min(x[i] / 300, 1) # Normalize up to 300ms
color_idx = int(time_normalized * (len(colors) - 1))
ax.fill_between(x[i:i+2], y[i:i+2], alpha=0.7, color=colors[color_idx])
ax.plot(x, y, color='white', linewidth=2.5)
# Performance thresholds
thresholds = [(100, 'Excellent', '#3b82f6'), (200, 'Good', '#22d3ee'),
(300, 'Acceptable', '#fbbf24'), (400, 'Slow', '#dc2626')]
for threshold, label, color in thresholds:
ax.axvline(threshold, color=color, linestyle='--', alpha=0.7, linewidth=1.5)
ax.text(threshold+5, max(y)*0.85, label, color=color, fontsize=9, rotation=90, va='top')
p95 = np.percentile(response_times, 95)
ax.axvline(p95, color='#fbbf24', linestyle='-', linewidth=2)
ax.text(p95+10, max(y)*0.5, f'P95: {p95:.0f}ms', color='#fbbf24', fontsize=10, fontweight='bold')
ax.set_xlabel('Response Time (ms)', fontsize=12, color='white', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='white', fontweight='500')
ax.set_title('API Response Time Distribution', fontsize=16, color='white', fontweight='bold', pad=15)
ax.tick_params(colors='white', labelsize=10)
for spine in ax.spines.values():
spine.set_color('#334155')
ax.set_xlim(0, 500)
ax.grid(True, alpha=0.1, color='white')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕