I am graphing the population of a town but to add randomness I am adding dummy values to emulate the look of a stock price etc. . It does workshowever the years have to be doubled as I am adding two x values. 1st is the real population and the 2nd is dummy population. The only way I can think of is multiplying the the range of y values by 2 but then when I put in 10 years it is basically saying its over 20 years. This is the full code below. Sorry if I explained it poorly.
from matplotlib import __version__
print('matplotlib version : ', __version__)
import matplotlib.pyplot as plt
import numpy as np
import random
def main():
P = 14613
K = 26760
e = np.exp(1)
R = 0.083
T = 0
year = 2006
font1 = {'family':'serif','color':'blue','size':20}
font2 = {'family':'serif','color':'darkred','size':15}
population = []
years = []
amount_years = int(input("How many years since 2006 do you want to calcuate the population: "))
for x in range(0, amount_years):
noise = random.uniform(-0.03,0.03)
equation = (P*K*(e**(R*T)))/((K-P)+P*(e**(R*T)))
dummy_pop = equation*noise
x = equation + dummy_pop
T += 1
population.append(equation)
population.append(x)
for x in range(0,amount_years):
years.append(year)
year += 0.5
xpoints = years
ypoints = population
plt.title("Portlaoise population since 2006", fontdict = font1, loc= 'left')
plt.xlabel("Years since 2006", fontdict = font2)
plt.ylabel("Population of Portlaoise", fontdict = font2)
plt.plot(xpoints, ypoints)
plt.show()
main()
I am graphing the population of a town but to add randomness I am adding dummy values to emulate the look of a stock price etc. . It does workshowever the years have to be doubled as I am adding two x values. 1st is the real population and the 2nd is dummy population. The only way I can think of is multiplying the the range of y values by 2 but then when I put in 10 years it is basically saying its over 20 years. This is the full code below. Sorry if I explained it poorly.
from matplotlib import __version__
print('matplotlib version : ', __version__)
import matplotlib.pyplot as plt
import numpy as np
import random
def main():
P = 14613
K = 26760
e = np.exp(1)
R = 0.083
T = 0
year = 2006
font1 = {'family':'serif','color':'blue','size':20}
font2 = {'family':'serif','color':'darkred','size':15}
population = []
years = []
amount_years = int(input("How many years since 2006 do you want to calcuate the population: "))
for x in range(0, amount_years):
noise = random.uniform(-0.03,0.03)
equation = (P*K*(e**(R*T)))/((K-P)+P*(e**(R*T)))
dummy_pop = equation*noise
x = equation + dummy_pop
T += 1
population.append(equation)
population.append(x)
for x in range(0,amount_years):
years.append(year)
year += 0.5
xpoints = years
ypoints = population
plt.title("Portlaoise population since 2006", fontdict = font1, loc= 'left')
plt.xlabel("Years since 2006", fontdict = font2)
plt.ylabel("Population of Portlaoise", fontdict = font2)
plt.plot(xpoints, ypoints)
plt.show()
main()
Share
Improve this question
edited Feb 14 at 22:15
pippo1980
3,0963 gold badges17 silver badges39 bronze badges
asked Feb 14 at 19:07
rorycostiganrorycostigan
1
2
|
1 Answer
Reset to default 0from matplotlib import __version__
print('matplotlib version : ', __version__)
import matplotlib.pyplot as plt
import numpy as np
import random
def main():
P = 14613
K = 26760
e = np.exp(1)
R = 0.083
T = 0
year = 2006
font1 = {'family':'serif','color':'blue','size':20}
font2 = {'family':'serif','color':'darkred','size':15}
population = []
years = []
amount_years = int(input("How many years since 2006 do you want to calcuate the population: "))
for x in range(0, amount_years):
noise = random.uniform(-0.03,0.03)
equation = (P*K*(e**(R*T)))/((K-P)+P*(e**(R*T)))
dummy_pop = equation*noise
x = int((equation + dummy_pop)/2)
T += 1
#population.append(equation)
population.append(x)
for x in range(0,amount_years):
years.append(year)
year += 0.5
xpoints = years
ypoints = population
plt.title("Portlaoise population since 2006", fontdict = font1, loc= 'left')
plt.xlabel("Years since 2006", fontdict = font2)
plt.ylabel("Population of Portlaoise", fontdict = font2)
plt.plot(xpoints, ypoints)
plt.show()
main()
Output:
matplotlib version : 3.8.4
using this bit:
for x in range(0, amount_years):
noise = random.uniform(-0.03,0.03)
equation = (P*K*(e**(R*T)))/((K-P)+P*(e**(R*T)))
dummy_pop = equation*noise
x = dummy_pop
T += 1
#population.append(equation)
population.append(x)
Output:
But I guess is uncorrect because I am not doubling Ys.
xpoints
andypoints
should have the same number of elements. I don't understand what you want to achieve and why you append two values topopulation
in each loop iteration. – jabaa Commented Feb 14 at 21:48