KDE Plot
Customer Segments KDE Comparison
Overlapping KDE plots comparing spending across customer segments.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
np.random.seed(47)
# Customer segments
budget = np.random.gamma(2, 30, 400)
standard = np.random.gamma(4, 40, 600)
premium = np.random.gamma(6, 60, 300)
fig, ax = plt.subplots(figsize=(12, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
# CLAUDE.md neon colors
segments = [
(budget, 'Budget', '#27D3F5'), # Cyan
(standard, 'Standard', '#F5B027'), # Amber
(premium, 'Premium', '#F5276C'), # Coral
]
x = np.linspace(0, 600, 500)
for data, label, color in segments:
kde = stats.gaussian_kde(data)
y = kde(x)
ax.fill_between(x, y, alpha=0.3, color=color)
ax.plot(x, y, color=color, linewidth=2.5, label=f'{label} (mean: ${np.mean(data):.0f})')
ax.set_xlabel('Monthly Spending ($)', fontsize=12, color='white', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='white', fontweight='500')
ax.set_title('Customer Spending by Segment', 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', fontsize=10)
ax.grid(True, alpha=0.1, color='white')
ax.set_xlim(0, 600)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
☕