我没有在Spyder 3.8中打印我的情节,我看不到关于这些地块为什么不会在地图窗格中打印的任何问题。我有未置的直列绘图
from random import random, randint
from matplotlib import pyplot as plt
class human:
def __init__(self, status):
self.status = status
self.time_infected = 0 #time ill at start is zero
self.building = list()
class place:
def __init__(self, place_id):
self.place_id = place_id
self.num_infected = 0 #number ill at start
def sim(n_places, n_uninfected, n_infected, iterations):
city = [place(i) for i in range(n_places)]
people = [human('healthy') for i in range(n_uninfected)] + [human('infected') for i in range(n_infected)]
uninfected_history = [n_uninfected]
infected_history = [n_infected]
recovered_history = [0]
deceased_history = [0]
days = [day for day in range(iterations)]
for day in days:
uninfected = 0
infected = 0
recovered = 0
deceased = 0
for human in people:
human.place = city[randint(0, len(city)-1)] #sending each person to one building during the day
for human in people:
if human.status == 'uninfected':
uninfected += 1
elif human.status == 'infected':
infected += 1
human.place.num_ill += 1
elif human.status == 'recovered':
recovered += 1
else:
deceased += 1
for human in people:
if human.status == 'infected' and human.time_infected < 15:
human.time_infected += 1
elif human.status == 'infected' and human.time_infected == 15:
if randint(0, 9) == 4:
human.status = 'deceased'
else:
human.status = 'recovered'
if human.status == 'uninfected':
infection_chance = 0.001*human.place.num_infected
if random() < infection_chance:
human.status = 'infected'
for place in city:
place.num_infected = 0
uninfected_history.append(uninfected)
infected_history.append(infected)
recovered_history.append(recovered)
deceased_history.append(deceased)
fig, axs = plt.subplots(4, sharex=True, sharey=False)
fig.suptitle('SIMPLE COVID19 SPREAD')
axs[0].plot(days, uninfected_history[:-1])
axs[0].set_title('Uninfected')
axs[1].plot(days, infected_history[:-1], 'tab:yellow')
axs[1].set_title('Infected')
axs[2].plot(days, recovered_history[:-1], 'tab:green')
axs[2].set_title('Recovered')
axs[3].plot(days, deceased_history[:-1], 'tab:red')
axs[3].set_title('Deceased')
plt.show()
sim(150, 49950, 50, 365)
from random import random, randint
from matplotlib import pyplot as plt
class human:
def __init__(self, status):
self.status = status
self.time_infected = 0 #time ill at start is zero
self.building = list()
class place:
def __init__(self, place_id):
self.place_id = place_id
self.num_infected = 0 #number ill at start
def sim(n_places, n_uninfected, n_infected, iterations):
city = [place(i) for i in range(n_places)]
people = [human('healthy') for i in range(n_uninfected)] + [human('infected') for i in range(n_infected)]
uninfected_history = [n_uninfected]
infected_history = [n_infected]
recovered_history = [0]
deceased_history = [0]
days = [day for day in range(iterations)]
for day in days:
uninfected = 0
infected = 0
recovered = 0
deceased = 0
for human in people:
human.place = city[randint(0, len(city)-1)] #sending each person to one building during the day
for human in people:
if human.status == 'uninfected':
uninfected += 1
elif human.status == 'infected':
infected += 1
human.place.num_ill += 1
elif human.status == 'recovered':
recovered += 1
else:
deceased += 1
for human in people:
if human.status == 'infected' and human.time_infected < 15:
human.time_infected += 1
elif human.status == 'infected' and human.time_infected == 15:
if randint(0, 9) == 4:
human.status = 'deceased'
else:
human.status = 'recovered'
if human.status == 'uninfected':
infection_chance = 0.001*human.place.num_infected
if random() < infection_chance:
human.status = 'infected'
for place in city:
place.num_infected = 0
uninfected_history.append(uninfected)
infected_history.append(infected)
recovered_history.append(recovered)
deceased_history.append(deceased)
fig, axs = plt.subplots(4, sharex=True, sharey=False)
fig.suptitle('SIMPLE COVID19 SPREAD')
axs[0].plot(days, uninfected_history[:-1])
axs[0].set_title('Uninfected')
axs[1].plot(days, infected_history[:-1], 'tab:yellow')
axs[1].set_title('Infected')
axs[2].plot(days, recovered_history[:-1], 'tab:green')
axs[2].set_title('Recovered')
axs[3].plot(days, deceased_history[:-1], 'tab:red')
axs[3].set_title('Deceased')
plt.show()
sim(150, 49950, 50, 365)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论