KDE Plot

Employee Productivity Score KDE

Density distribution of productivity scores by department

Output
Employee Productivity Score KDE
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde

np.random.seed(888)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'
GRID_COLOR = '#e5e7eb'

# Productivity scores (0-100)
engineering = np.random.normal(78, 10, 300)
sales = np.random.normal(72, 14, 300)
marketing = np.random.normal(75, 12, 300)
support = np.random.normal(70, 11, 300)

fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

x_range = np.linspace(30, 100, 500)

for data, color, label in [(engineering, '#4927F5', 'Engineering'), 
                            (sales, '#6CF527', 'Sales'),
                            (marketing, '#F5B027', 'Marketing'),
                            (support, '#F5276C', 'Support')]:
    kde = gaussian_kde(data)
    density = kde(x_range)
    ax.plot(x_range, density, color=color, linewidth=2.5, label=label)
    ax.fill_between(x_range, density, alpha=0.2, color=color)

ax.set_xlabel('Productivity Score', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('Density', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Employee Productivity by Department', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

ax.tick_params(colors=TEXT_COLOR, labelsize=10)
for spine in ax.spines.values():
    spine.set_color(GRID_COLOR)
ax.yaxis.grid(True, color=GRID_COLOR, linewidth=0.5, alpha=0.7)
ax.legend(facecolor=BG_COLOR, edgecolor=GRID_COLOR, labelcolor=TEXT_COLOR, fontsize=10)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support