2D Histogram

Salary vs Experience

2D histogram of employee salaries versus years of work experience.

Output
Salary vs Experience
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(42)

# Career data
experience = np.clip(np.random.exponential(5, 5000), 0, 35)
salary = 40000 + experience * 5000 + np.random.normal(0, 15000, 5000)
salary = np.clip(salary, 30000, 250000)

fig, ax = plt.subplots(figsize=(10, 8), facecolor='#020B14')
ax.set_facecolor('#020B14')

# Custom colormap: purple to yellow
colors = ['#020B14', '#1a0d2e', '#4927F5', '#F5B027', '#F5D327']
cmap = LinearSegmentedColormap.from_list('career', colors, N=256)

h = ax.hist2d(experience, salary/1000, bins=40, cmap=cmap, cmin=1)
cbar = plt.colorbar(h[3], ax=ax, pad=0.02)
cbar.set_label('Employees', color='white', fontsize=11)
cbar.ax.yaxis.set_tick_params(color='white')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='white')

ax.set_xlabel('Years of Experience', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Salary ($K)', fontsize=11, color='white', fontweight='500')
ax.set_title('Salary vs Experience', fontsize=14, color='white', fontweight='bold', pad=15)

ax.tick_params(colors='white', labelsize=9)
for spine in ax.spines.values():
    spine.set_color('#333333')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support