Linear Regression Plot

Training Hours vs Race Time

Athletic performance improvement analysis

Output
Training Hours vs Race Time
Python
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

np.random.seed(414)
BG_COLOR = '#ffffff'
TEXT_COLOR = '#1f2937'

n = 65
training = np.random.uniform(5, 50, n)
race_time = 60 - 0.6 * training + np.random.normal(0, 5, n)

df = pd.DataFrame({'Training Hours/Week': training, 'Race Time (min)': race_time})

fig, ax = plt.subplots(figsize=(10, 6), facecolor=BG_COLOR)
ax.set_facecolor(BG_COLOR)

sns.regplot(
    data=df,
    x='Training Hours/Week',
    y='Race Time (min)',
    scatter_kws={'color': '#6CF527', 'alpha': 0.6, 's': 55, 'edgecolor': 'white', 'linewidths': 0.5},
    line_kws={'color': '#F54927', 'linewidth': 2.5},
    ci=95,
    ax=ax
)

for collection in ax.collections[1:]:
    collection.set_facecolor('#F54927')
    collection.set_alpha(0.15)

corr = np.corrcoef(training, race_time)[0, 1]
ax.text(0.95, 0.95, 'r = %.3f' % corr, transform=ax.transAxes, fontsize=12,
        color='#F54927', fontweight='bold', va='top', ha='right',
        bbox=dict(boxstyle='round,pad=0.3', facecolor='#f8fafc', edgecolor='#e5e7eb'))

ax.set_xlabel('Training Hours/Week', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_ylabel('10K Race Time (min)', fontsize=12, color=TEXT_COLOR, fontweight='500')
ax.set_title('Training vs Race Performance', fontsize=14, color=TEXT_COLOR, fontweight='bold', pad=15)

ax.tick_params(colors='#374151', labelsize=10)
for spine in ax.spines.values():
    spine.set_color('#e5e7eb')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support