Linear Regression Plot
Cortisol Circadian Rhythm
Endocrinology temporal pattern with sinusoidal fit
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(222)
# Circadian data
hours = np.linspace(0, 24, 60)
# Cortisol peaks around 8am
cortisol = 15 + 8 * np.sin((hours - 2) * np.pi / 12) + np.random.normal(0, 1.5, 60)
cortisol = np.clip(cortisol, 3, 28)
# Fit curve
h_smooth = np.linspace(0, 24, 200)
c_smooth = 15 + 8 * np.sin((h_smooth - 2) * np.pi / 12)
fig, ax = plt.subplots(figsize=(10, 7), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
ax.fill_between(h_smooth, c_smooth - 2, c_smooth + 2, color='#C82909', alpha=0.12, linewidth=0)
ax.plot(h_smooth, c_smooth, color='#C82909', linewidth=2.5, zorder=3)
ax.scatter(hours, cortisol, c='#27F5B0', s=55, alpha=0.85, edgecolors='white', linewidths=0.4, zorder=4)
# Time markers
for h, label in [(6, 'wake'), (12, 'noon'), (22, 'sleep')]:
ax.axvline(x=h, color='#333333', linestyle=':', linewidth=1, alpha=0.5)
ax.text(h, 27, label, fontsize=9, color='#666666', ha='center')
# Peak annotation
ax.scatter([8], [23], c='#F5276C', s=100, marker='v', zorder=5)
ax.text(8.5, 24.5, 'peak', fontsize=9, color='#F5276C')
for spine in ['top', 'right']:
ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
ax.spines[spine].set_color('#333333')
ax.set_xlabel('Time of Day (hours)', fontsize=12, color='white', fontweight='500', labelpad=10)
ax.set_ylabel('Cortisol (μg/dL)', fontsize=12, color='white', fontweight='500', labelpad=10)
ax.set_title('Circadian Cortisol Pattern', fontsize=15, color='white', fontweight='bold', pad=20, loc='left')
ax.tick_params(colors='#666666', labelsize=10, length=0)
ax.set_xlim(0, 24)
ax.set_xticks([0, 6, 12, 18, 24])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Linear Regression Plot examples
☕