Linear Regression Plot
Population Growth Dynamics
Logistic growth model with carrying capacity annotation
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(666)
# Population data
time = np.linspace(0, 50, 60)
K = 1000 # carrying capacity
r = 0.15 # growth rate
N0 = 50
pop = K / (1 + ((K - N0) / N0) * np.exp(-r * time)) + np.random.normal(0, 30, 60)
# Theoretical curve
t_smooth = np.linspace(0, 50, 200)
pop_smooth = K / (1 + ((K - N0) / N0) * np.exp(-r * t_smooth))
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)
# Carrying capacity line
ax.axhline(y=K, color='#F54927', linestyle='--', linewidth=1.5, alpha=0.6)
ax.text(48, K + 30, f'K = {K}', fontsize=10, color='#F54927', ha='right')
ax.fill_between(t_smooth, pop_smooth - 40, pop_smooth + 40, color='#5314E6', alpha=0.1, linewidth=0, zorder=2)
ax.plot(t_smooth, pop_smooth, color='#5314E6', linewidth=2.5, zorder=3)
ax.scatter(time, pop, c='#F5B027', s=55, alpha=0.85, edgecolors='white', linewidths=0.6, zorder=4)
# Growth phases
ax.annotate('exponential', xy=(10, 200), fontsize=9, color='#666666')
ax.annotate('decelerating', xy=(25, 650), fontsize=9, color='#666666')
ax.annotate('equilibrium', xy=(42, 920), fontsize=9, color='#666666')
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('Time (generations)', fontsize=12, color='#333333', fontweight='500', labelpad=10)
ax.set_ylabel('Population Size (N)', fontsize=12, color='#333333', fontweight='500', labelpad=10)
ax.set_title('Logistic Population Growth', fontsize=15, color='#1a1a1a', fontweight='bold', pad=20, loc='left')
ax.tick_params(colors='#666666', labelsize=10, length=0)
ax.set_ylim(0, 1150)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Linear Regression Plot examples
☕