Linear Regression Plot

Cardiac Output Response

Exercise physiology with workload-dependent heart function

Output
Cardiac Output Response
Python
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

np.random.seed(888)

# Exercise physiology
workload = np.random.uniform(25, 300, 55)  # Watts
cardiac_output = 5 + 0.025 * workload + np.random.normal(0, 1.2, 55)

slope, intercept, r_value, _, _ = stats.linregress(workload, cardiac_output)
x_fit = np.linspace(20, 310, 100)
y_fit = slope * x_fit + intercept

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

ax.yaxis.grid(True, color='#f0f0f0', linewidth=1, zorder=1)
ax.xaxis.grid(True, color='#f0f0f0', linewidth=1, zorder=1)

# Exercise zones
ax.axvspan(25, 100, alpha=0.05, color='#6CF527', zorder=1)
ax.axvspan(100, 200, alpha=0.05, color='#F5B027', zorder=1)
ax.axvspan(200, 310, alpha=0.05, color='#F5276C', zorder=1)
ax.text(62, 3, 'light', fontsize=8, color='#6CF527', ha='center')
ax.text(150, 3, 'moderate', fontsize=8, color='#F5B027', ha='center')
ax.text(255, 3, 'vigorous', fontsize=8, color='#F5276C', ha='center')

ax.fill_between(x_fit, y_fit - 1.5, y_fit + 1.5, color='#C82909', alpha=0.1, linewidth=0, zorder=2)
ax.plot(x_fit, y_fit, color='#C82909', linewidth=2.5, zorder=3)
ax.scatter(workload, cardiac_output, c='#4927F5', s=55, alpha=0.85, edgecolors='white', linewidths=0.6, zorder=4)

ax.text(0.97, 0.05, f'ΔQ/ΔW = {slope*100:.1f} mL/min/W\nR² = {r_value**2:.3f}',
        transform=ax.transAxes, fontsize=10, color='#555555', ha='right', va='bottom', family='monospace')

for spine in ['top', 'right']:
    ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
    ax.spines[spine].set_color('#cccccc')

ax.set_xlabel('Workload (Watts)', fontsize=12, color='#333333', fontweight='500', labelpad=10)
ax.set_ylabel('Cardiac Output (L/min)', fontsize=12, color='#333333', fontweight='500', labelpad=10)
ax.set_title('Exercise Cardiac Response', fontsize=15, color='#1a1a1a', fontweight='bold', pad=20, loc='left')
ax.tick_params(colors='#666666', labelsize=10, length=0)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support