2D Histogram

Athlete Performance Profile

Speed vs stamina distribution by player type

Output
Athlete Performance Profile
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

# Sports performance data
np.random.seed(42)

# Different player types with distinct profiles
n_players = 3000

# Sprinters: high speed, lower stamina
speed_sprint = np.random.normal(92, 5, n_players // 3)
stamina_sprint = np.random.normal(55, 10, n_players // 3)

# Endurance: lower speed, high stamina  
speed_endur = np.random.normal(70, 8, n_players // 3)
stamina_endur = np.random.normal(88, 6, n_players // 3)

# All-rounders: balanced
speed_all = np.random.normal(80, 7, n_players // 3)
stamina_all = np.random.normal(75, 8, n_players // 3)

speed = np.concatenate([speed_sprint, speed_endur, speed_all])
stamina = np.concatenate([stamina_sprint, stamina_endur, stamina_all])

speed = np.clip(speed, 50, 100)
stamina = np.clip(stamina, 40, 100)

# Sports dark theme
plt.style.use('dark_background')
fig, ax = plt.subplots(figsize=(10, 8))
fig.patch.set_facecolor('#0a0a12')
ax.set_facecolor('#0a0a12')

# Custom colormap - energetic orange-yellow
colors = ['#0a0a12', '#1a1020', '#2a1a30', '#4a2a40', '#7a3a50', 
          '#aa4a55', '#da6a50', '#fa8a40', '#ffaa30', '#ffcc20', '#ffee10']
cmap = LinearSegmentedColormap.from_list('sports', colors, N=256)

# 2D histogram
h = ax.hist2d(speed, stamina, bins=45, cmap=cmap, cmin=1)

# Performance zones
ax.axvline(x=85, color='#ffaa30', linestyle='--', alpha=0.6, linewidth=1.5)
ax.axhline(y=80, color='#ffaa30', linestyle='--', alpha=0.6, linewidth=1.5)

# Zone labels
ax.text(93, 48, 'Sprinters', fontsize=10, color='#ffcc20', alpha=0.8, fontweight='500')
ax.text(55, 92, 'Endurance', fontsize=10, color='#ffcc20', alpha=0.8, fontweight='500')
ax.text(82, 78, 'Elite', fontsize=11, color='#ffffff', alpha=0.9, fontweight='bold')

# Styled colorbar
cbar = plt.colorbar(h[3], ax=ax, pad=0.02, shrink=0.85)
cbar.ax.set_facecolor('#0a0a12')
cbar.set_label('Player Count', fontsize=11, color='#e0c0a0', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#e0c0a0')
cbar.outline.set_edgecolor('#3a2a20')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#e0c0a0', fontsize=9)

# Labels
ax.set_xlabel('Speed Rating', fontsize=13, color='#e0c0a0', fontweight='600', labelpad=10)
ax.set_ylabel('Stamina Rating', fontsize=13, color='#e0c0a0', fontweight='600', labelpad=10)
ax.set_title('Athlete Performance Distribution', fontsize=16, color='white', 
             fontweight='bold', pad=20)

# Style axes
ax.tick_params(colors='#c0a080', labelsize=10, length=0)
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Statistical

Did this help you?

Support PyLucid to keep it free & growing

Support