add plot range
This commit is contained in:
@ -1,25 +1,35 @@
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
# Initial population
|
# Initial population at year 1
|
||||||
population = 1_000_000
|
initial_population = 1_000_000
|
||||||
death_rate = 0.10
|
death_rate = 0.10
|
||||||
years = np.arange(4000, 10001, 500) # 4000 to 10000 years in 500-year intervals
|
|
||||||
|
|
||||||
# Calculate population after each 500-year interval
|
# Start and stop years for the graph
|
||||||
|
start_year = 4000
|
||||||
|
stop_year = 10000
|
||||||
|
interval = 500 # Interval for plotting data points
|
||||||
|
|
||||||
|
# Calculate the population at the start of the start_year
|
||||||
|
current_population = initial_population
|
||||||
|
for _ in range(start_year // 100): # Dividing by 100 as the death rate is applied every 100 years
|
||||||
|
current_population -= death_rate * current_population
|
||||||
|
|
||||||
|
# Now calculate and plot the population from start_year to stop_year
|
||||||
|
years = np.arange(start_year, stop_year + 1, interval)
|
||||||
population_values = []
|
population_values = []
|
||||||
for year in years:
|
for year in years:
|
||||||
# Apply the death rate for each 500-year period (5 times for each interval)
|
# Apply the death rate for each interval (interval/100 times for each period)
|
||||||
for _ in range(5):
|
for _ in range(interval // 100):
|
||||||
population -= death_rate * population
|
current_population -= death_rate * current_population
|
||||||
population_values.append(population)
|
population_values.append(current_population)
|
||||||
|
|
||||||
# Create the graph with labels for each data point
|
# Create the graph with labels for each data point
|
||||||
plt.figure(figsize=(8, 6))
|
plt.figure(figsize=(8, 6))
|
||||||
plt.plot(years, population_values, marker='o', linestyle='-', color='b')
|
plt.plot(years, population_values, marker='o', linestyle='-', color='b')
|
||||||
plt.xlabel('Years')
|
plt.xlabel('Years')
|
||||||
plt.ylabel('Population')
|
plt.ylabel('Population')
|
||||||
plt.title('Population Projection from Year 4000')
|
plt.title(f'Population Projection from Year {start_year} to {stop_year}')
|
||||||
|
|
||||||
# Adding labels to the data points
|
# Adding labels to the data points
|
||||||
for i, txt in enumerate(population_values):
|
for i, txt in enumerate(population_values):
|
||||||
|
Reference in New Issue
Block a user