0% found this document useful (0 votes)
15 views4 pages

15 - PracticeC (4) - JupyterLab

intro to data science 15c

Uploaded by

bhuvinarkhede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

15 - PracticeC (4) - JupyterLab

intro to data science 15c

Uploaded by

bhuvinarkhede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

10/18/24, 7:59 PM 15_PracticeC

✅ Bhuvi Narkhede

15C: What if the growth projections change for the


population?
As you saw in deer population projections, different parameters effect the growth model,
sometimes significantly. Think about how a 10% growth rate compared to a 25% growth
rate. Both of these growth rates area actually quite high for general population changes.

✏ Calculate what the population projections for growth would be if the deer population
was more inline with historical models for wild animal growth. Consider the following more
common values of the growth rate:

$k_R =$ 0.01, 0.03, 0.05, 0.07, and 0.09

Put the lines for all five growth models for the deer population on the same plot. This time,
add a legend to your graph that includes what each graph represents. Use plt.legend()
to add a legend to the plot.

In order for your graph to have an appropriate legend, make sure that each of your curves
has a label parameter at the end of the plot command.

In [4]: import math


import matplotlib.pyplot as plt

def deer_growth(P0, K, k_R, time_list):


A = (K - P0) / P0
population_estimates = []
for t in time_list:
Pt = K / (1 + A * math.exp(-k_R * t))
population_estimates.append(Pt)
return population_estimates

P0 = 2400
K = 3800
time_list = list(range(0, 31))

first_rate = deer_growth(P0, K, 0.01, time_list)


second_rate = deer_growth(P0, K, 0.03, time_list)
third_rate = deer_growth(P0, K, 0.05, time_list)
fourth_rate = deer_growth(P0, K, 0.07, time_list)
fifth_rate = deer_growth(P0, K, 0.09, time_list)

plt.figure(figsize=(10, 6))
plt.plot(time_list, first_rate, label='k_R = 0.01')
plt.plot(time_list, second_rate, label='k_R = 0.03')
plt.plot(time_list, third_rate, label='k_R = 0.05')
plt.plot(time_list, fourth_rate, label='k_R = 0.07')

localhost:8888/lab/tree/15_PracticeC.ipynb? 1/4
10/18/24, 7:59 PM 15_PracticeC

plt.plot(time_list, fifth_rate, label='k_R = 0.09')

plt.title('Deer Population Predictions based on Growth Rate')


plt.xlabel('Years')
plt.ylabel('Deer Population')
plt.legend()
plt.show()

Look back at your graph above. Did you remember to add titles and labels to the axis? If not, go back and do that
now.Understanding the implications of your data is an important part of data analysis. Think about the different growth projections
in your graph above. What types of changes could cause the deer population to be more inline with one of the smaller growth
rates? Write your ideas and insight here. (Do a little research so your answers are based in factual knowledge.)

Zooming in to a section using xlim and ylim


✏ Sometimes it makes more sense to zoom into a certain time frame, versus a span of
many years to see the individual changes over a shorter time span. To accomplish this, we
need to change some of the parameters and rules for the graph.

Without changing the years of calculation, modify the plot so the viewable part of your
graph is only the years from 2012 - 2022. The goal is to change the viewable area to
reduce the x_axis to only include these years. Scale the y_axis accordingly, based on the
data. This can be done using the xlim and ylim functions in pyplot . Take a few
minutes to explore the internet for information on how these two commands can be
used.
Plot each year as an individual point instead of the lines/curves used previously. Each
growth rate should be represented by a different figure and color. The figures should
include a triangle, a star, a circle, and other shapes of your choosing.

localhost:8888/lab/tree/15_PracticeC.ipynb? 2/4
10/18/24, 7:59 PM 15_PracticeC

Ensure that the plot has all of the appropriate labels, titles, and legend.

In [8]: # Type your code here


import math
import matplotlib.pyplot as plt

def deer_growth(P0, K, k_R, time_list):


A = (K - P0) / P0
population_estimates = []
for t in time_list:
Pt = K / (1 + A * math.exp(-k_R * t))
population_estimates.append(Pt)
return population_estimates

P0 = 2400
K = 3800
time_list = list(range(0, 31))

first_rate = deer_growth(P0, K, 0.01, time_list)


second_rate = deer_growth(P0, K, 0.03, time_list)
third_rate = deer_growth(P0, K, 0.05, time_list)
fourth_rate = deer_growth(P0, K, 0.07, time_list)
fifth_rate = deer_growth(P0, K, 0.09, time_list)

plt.figure(figsize=(10, 6))

plt.plot(time_list, first_rate, 'v', label='k_R = 0.01')


plt.plot(time_list, second_rate, '*', label='k_R = 0.03')
plt.plot(time_list, third_rate, 'o', label='k_R = 0.05')
plt.plot(time_list, fourth_rate, 's', label='k_R = 0.07')
plt.plot(time_list, fifth_rate, 'D', label='k_R = 0.09')

plt.title('Deer Population Predictions (2012-2022) based on Growth Rate')


plt.xlabel('Years')
plt.ylabel('Deer Population')

plt.xlim(2, 12)
plt.ylim(2400, 3500)

plt.legend()
plt.show()

localhost:8888/lab/tree/15_PracticeC.ipynb? 3/4
10/18/24, 7:59 PM 15_PracticeC

localhost:8888/lab/tree/15_PracticeC.ipynb? 4/4

You might also like