Mirror Chart

Male vs Female Salary Distribution

Mirror density comparing salary distributions with statistical annotations and glow effects

Output
Male vs Female Salary Distribution
Python
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde

np.random.seed(42)
BG_COLOR = '#0a0a0f'

# Salary data (thousands)
male = np.random.normal(78, 18, 1200)
female = np.random.normal(65, 16, 1200)

fig, ax = plt.subplots(figsize=(12, 7), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

x = np.linspace(15, 140, 500)

# Male (top) with glow effect
kde_m = gaussian_kde(male)
y_m = kde_m(x)
ax.fill_between(x, y_m, alpha=0.15, color='#27D3F5')
ax.fill_between(x, y_m, alpha=0.08, color='#27D3F5')
ax.plot(x, y_m, color='#27D3F5', linewidth=4, alpha=0.3)
ax.plot(x, y_m, color='#27D3F5', linewidth=2, label=f'Male (μ=${np.mean(male):.0f}K)')

# Female (bottom) with glow effect
kde_f = gaussian_kde(female)
y_f = kde_f(x) * -1
ax.fill_between(x, y_f, alpha=0.15, color='#F5276C')
ax.fill_between(x, y_f, alpha=0.08, color='#F5276C')
ax.plot(x, y_f, color='#F5276C', linewidth=4, alpha=0.3)
ax.plot(x, y_f, color='#F5276C', linewidth=2, label=f'Female (μ=${np.mean(female):.0f}K)')

# Center axis
ax.axhline(0, color='#444444', linewidth=1.5)

# Mean lines with annotations
m_mean, f_mean = np.mean(male), np.mean(female)
ax.axvline(m_mean, color='#27D3F5', linestyle='--', alpha=0.5, linewidth=1.5)
ax.axvline(f_mean, color='#F5276C', linestyle='--', alpha=0.5, linewidth=1.5)

# Gap annotation
gap = ((m_mean - f_mean) / f_mean) * 100
ax.annotate('', xy=(m_mean, max(y_m)*0.7), xytext=(f_mean, max(y_m)*0.7),
            arrowprops=dict(arrowstyle='<->', color='#F5B027', lw=2))
ax.text((m_mean + f_mean)/2, max(y_m)*0.75, f'Gap: {gap:.1f}%', 
        ha='center', fontsize=11, color='#F5B027', fontweight='bold')

# Stats box
stats = f"Δμ = ${m_mean-f_mean:.1f}K | Male σ={np.std(male):.1f} | Female σ={np.std(female):.1f}"
ax.text(0.5, 0.98, stats, transform=ax.transAxes, ha='center', va='top',
        fontsize=10, color='#888888', fontfamily='monospace',
        bbox=dict(boxstyle='round,pad=0.4', facecolor=BG_COLOR, edgecolor='#333333'))

ax.set_xlabel('Annual Salary ($K)', fontsize=12, color='white', fontweight='500')
ax.set_ylabel('Density', fontsize=12, color='white', fontweight='500')
ax.set_title('Gender Pay Gap Analysis', fontsize=16, color='white', fontweight='bold', pad=20)

ax.tick_params(colors='#888888', labelsize=10)
ax.set_yticks([])
for spine in ['top', 'right']:
    ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
    ax.spines[spine].set_color('#333333')
ax.legend(loc='upper right', facecolor=BG_COLOR, edgecolor='#333333', 
          labelcolor='white', fontsize=10, framealpha=0.9)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support