KDE Plot
ML Model Inference Time KDE
Density distribution of ML model inference latency across deployment platforms
Output
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
np.random.seed(333)
BG_COLOR = '#0a0a0f'
TEXT_COLOR = 'white'
# Inference time in ms
cloud_gpu = np.random.lognormal(2.5, 0.4, 500)
edge_device = np.random.lognormal(3.5, 0.5, 500)
mobile = np.random.lognormal(4.2, 0.6, 500)
fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)
x_range = np.linspace(0, 300, 500)
for data, color, label in [(cloud_gpu, '#4927F5', 'Cloud GPU'),
(edge_device, '#27F5B0', 'Edge Device'),
(mobile, '#F5B027', 'Mobile')]:
data_clipped = data[data < 300]
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(100, color='#F5276C', linestyle='--', alpha=0.8, linewidth=2, label='Real-time: 100ms')
ax.set_xlabel('Inference Time (ms)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('ML Model Inference Latency by Platform', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)
ax.set_xlim(0, 300)
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
☕