Hexbin Plot

Sprint Acceleration Profile

Sports science hexbin of velocity vs acceleration during sprints

Output
Sprint Acceleration Profile
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(6666)
velocity = np.random.uniform(0, 10, 7000)
acceleration = 8 * np.exp(-velocity/3) + np.random.normal(0, 1, 7000)
acceleration = np.clip(acceleration, -2, 10)

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

colors = ['#ffedd5', '#fed7aa', '#fdba74', '#fb923c', '#f97316', '#ea580c', '#c2410c', '#9a3412']
cmap = LinearSegmentedColormap.from_list('sport', colors, N=256)

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

cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.outline.set_edgecolor('#fed7aa')
cbar.ax.tick_params(colors='#c2410c', labelsize=9)
cbar.set_label('Data Points', color='#c2410c', fontsize=10)

ax.set_xlabel('Velocity (m/s)', color='#c2410c', fontsize=11)
ax.set_ylabel('Acceleration (m/s²)', color='#c2410c', fontsize=11)
ax.tick_params(colors='#c2410c', labelsize=10)
ax.axhline(0, color='#fb923c', linewidth=0.5, linestyle='--', alpha=0.5)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#fed7aa')
ax.spines['bottom'].set_color('#fed7aa')

plt.tight_layout()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support