KDE Plot

Application Memory Usage Distribution

KDE showing memory consumption patterns across applications.

Output
Application Memory Usage Distribution
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(61)

# Memory usage (MB) - mix of light and heavy apps
light_apps = np.random.exponential(50, 400)
medium_apps = np.random.normal(200, 80, 400)
heavy_apps = np.random.normal(500, 150, 200)
memory = np.concatenate([light_apps, medium_apps, heavy_apps])
memory = memory[memory > 0]

kde = stats.gaussian_kde(memory)
x = np.linspace(0, 1000, 500)
y = kde(x)

fig, ax = plt.subplots(figsize=(12, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

# Gradient by memory usage
for i in range(len(x)-1):
    if x[i] < 100:
        color = '#27F5B0'  # Light - mint
    elif x[i] < 300:
        color = '#27D3F5'  # Medium - cyan
    elif x[i] < 500:
        color = '#F5B027'  # Heavy - amber
    else:
        color = '#F5276C'  # Very heavy - coral
    ax.fill_between(x[i:i+2], y[i:i+2], alpha=0.6, color=color)

ax.plot(x, y, color='#27F5B0', linewidth=3)
ax.plot(x, y, color='#27F5B0', linewidth=8, alpha=0.2)

# Percentiles
p50 = np.percentile(memory, 50)
p90 = np.percentile(memory, 90)
ax.axvline(p50, color='#27D3F5', linestyle='--', linewidth=2, label=f'P50: {p50:.0f}MB')
ax.axvline(p90, color='#F5B027', linestyle='--', linewidth=2, label=f'P90: {p90:.0f}MB')

ax.set_xlabel('Memory Usage (MB)', fontsize=12, color='white', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='white', fontweight='500')
ax.set_title('Application Memory Consumption 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.legend(loc='upper right', facecolor='#1e293b', edgecolor='#334155', labelcolor='white')
ax.grid(True, alpha=0.1, color='white')
ax.set_xlim(0, 1000)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support