0

I am a complete rookie at this Python, and I keep getting hung up on absolutely everything and it is incredibly frustrating. I've created a population growth model that does what I want it to. The problem comes when I try to add other growth rates to the same plot. I can't figure it out.

%matplotlib inline                 
import matplotlib.pyplot as plt 
import math

#Defining funciton to calculate population growth over time
def calc_population(P0, K, kR, A, t0, t):
    A = ((K - P0)/P0)
    Pt = []
    for x in range(len(t)):
        denom = (1+A*math.exp(-kR*(t[x]-t0)))
        Pt.append(K/denom)
    return(Pt)

#Defining parameters
P0 = 1000000000
K = 12000000000
kR = 0.01
list_years = list(range(1800, 2100, 1))
t0 = 1800

# Running function
calc_population(P0, K, kR, A, t0, list_years)
    
plt.plot(Pt,list_years, "b", linewidth = 2)
plt.axis([1000000000,13000000000,1800,2200])
plt.title("Population Growth Over Time")
plt.xlabel("Population")
plt.ylabel("Years") 

P0 = 1000000000
K = 12000000000
kR = [0.01, 0.015, 0.02, 0.03, 0.04, 0.05]
list_years = list(range(1800, 2100, 1))
t0 = 1800

pop_other_rates = []

for r in range(len(kR)):
    Pt=calc_population(P0, K, kR[r], A, t0, list_years)
    pop_other_rates.append(Pt)

plt.plot(Pt, list_years,"b", linewidth = 2)
plt.axis([1000000000,13000000000,1800,2200])
plt.title("Population Growth Over Time")
plt.xlabel("Population")
plt.ylabel("Years")

The last chunk of code just prints out a plot with the 0.01 kR value, and I need a new line for each kR value in the last chunk of code. I've been at this for well over an hour now and I can't find a way to make it work. Help?

redleg_64
  • 27
  • 7

0 Answers0