Hexbin Plot

Endurance Athlete Metrics

VO2 max vs lactate threshold for endurance athletes.

Output
Endurance Athlete Metrics
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(42)
n_athletes = 5000

vo2_max = np.random.normal(55, 12, n_athletes)
vo2_max = np.clip(vo2_max, 30, 85)

lt_percent = 0.7 + 0.003 * vo2_max + np.random.normal(0, 0.06, n_athletes)
lt_percent = np.clip(lt_percent, 0.6, 0.95) * 100

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

colors = ['#f0fdf4', '#dcfce7', '#bbf7d0', '#86efac', '#4ade80', 
          '#22c55e', '#16a34a', '#15803d', '#166534', '#14532d']
cmap = LinearSegmentedColormap.from_list('green', colors, N=256)

hb = ax.hexbin(vo2_max, lt_percent, gridsize=30, cmap=cmap, mincnt=1,
               edgecolors='white', linewidths=0.3)

ax.axvline(x=70, color='#16a34a', linestyle='--', alpha=0.7, linewidth=2, label='Elite VO2 (>70)')
ax.axhline(y=85, color='#0ea5e9', linestyle='--', alpha=0.7, linewidth=2, label='Elite LT (>85%)')

from matplotlib.patches import Rectangle
elite = Rectangle((70, 85), 15, 10, fill=False, edgecolor='#eab308', 
                   linewidth=2.5, linestyle='-', alpha=0.9)
ax.add_patch(elite)
ax.text(77.5, 92, 'World Class', fontsize=10, color='#ca8a04', ha='center', fontweight='700')

cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.85)
cbar.set_label('Athlete Count', fontsize=11, color='#14532d', labelpad=10)
cbar.ax.yaxis.set_tick_params(color='#166534')
cbar.outline.set_edgecolor('#bbf7d0')
plt.setp(plt.getp(cbar.ax.axes, 'yticklabels'), color='#166534', fontsize=9)

ax.set_xlabel('VO2 Max (ml/kg/min)', fontsize=12, color='#14532d', fontweight='600', labelpad=12)
ax.set_ylabel('Lactate Threshold (% VO2)', fontsize=12, color='#14532d', fontweight='600', labelpad=12)
ax.set_title('Endurance Athlete Performance', fontsize=16, color='#052e16', fontweight='700', pad=20)

ax.tick_params(colors='#166534', labelsize=10, length=0)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#bbf7d0')
ax.spines['bottom'].set_color('#bbf7d0')

ax.legend(loc='lower right', fontsize=9, frameon=True, facecolor='white', 
          edgecolor='#bbf7d0', labelcolor='#14532d')
ax.grid(True, alpha=0.3, color='#bbf7d0', linestyle='-', linewidth=0.5)
ax.set_axisbelow(True)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support