Jul-30-2017, 10:02 AM
Hi,
I am trying to write a short program to visualise population dynamics in lemming populations.
The code I have below works ok but only gives me a scatter plot (obvs as I have use pot.scatter()!!!)
What I really want is to get the scatter graph but with a line connecting all the points.
I have tried plt.plot() but cannot get more than 1 point plotted. It doesn't seem to run through the iteration.
I have tried to do def() and then use while loops but without success.
Any help on getting the iterations plotting with a line joining each point on the graph would be GREATLY appreciated!
I am a Biology teacher and would like to use this sort of model with my students.
Thanks!
I am trying to write a short program to visualise population dynamics in lemming populations.
The code I have below works ok but only gives me a scatter plot (obvs as I have use pot.scatter()!!!)
What I really want is to get the scatter graph but with a line connecting all the points.
I have tried plt.plot() but cannot get more than 1 point plotted. It doesn't seem to run through the iteration.
I have tried to do def() and then use while loops but without success.
Any help on getting the iterations plotting with a line joining each point on the graph would be GREATLY appreciated!
I am a Biology teacher and would like to use this sort of model with my students.
Thanks!
import matplotlib.pyplot as plt
## Set the inital population size using user input
init_pop = float(input("What would you like to set the initial population as? (Please note the maximum population size is 1000)"))
print ("Ok, initial population set at", init_pop, " .")
## The logistic equation that this program models requires the initial population size to be a proportion of the maixmum population size
pop= init_pop/1000
##Set the number of years to model
Years = float(input("How many years do you want to run the simulation for? "))
print ("Ok, runnning the simulation for", Years, "years. " )
## Set the growth rate. Nb as this changes the population dynamics vary wildly from chaotic to stable population size
rate = float(input("What would you like to set the growth rate as?"))
print ("Ok, growth rate is set at", rate, " .")
##This is where I use the input numbers to do the maths part of the logistic equation
for x in range(int(Years)):
Pop_new = rate*pop*(1-pop)
pop = Pop_new
plt.scatter(x+1, Pop_new*100)
print (x+1, Pop_new*1000)
plt.ylabel("Population Size")
plt.xlabel("Years")
plt.show()
