I have written a function that simulates the spread of an epidemic and am trying to visualize the spread in a scatterplot. The x value is the generation and the y value is the number of people infected that generation. However, when I plot this graph I get something I have never seen before. The plot does not even respond to color scheme changes. Why might this be happening and is there a way to display the data as one would in a conventional scatterplot? This happens for any number of iterations but gets worse with more iterations.
This is what the plot displays currently: plot
N=np.zeros(1000)
for x in range(99):
infections = branch()
list_length=len(infections)
sumOfElements=0
for i in range(list_length):
infectionsum=sumOfElements+infections[i]
N[x] = infectionsum
#print(infections)
genhouse = [0,1,2,3,4,5,6,7,8,9]
#s = [3*s**2 for s in infections]
plt.scatter(genhouse, infections)
#plt.scatter(x, y, s=area, c=colors, alpha=0.5)
sum = np.sum(N)
print("the average epidemic size is", sum)
plt.title('Infections across Generations')
plt.xlabel('Generation')
plt.ylabel('Number of Infections')
plt.show()
I have included the function that simulates the disease below for additional reference.
def branch():
r = .95 #reproduction number
manygens = 10 #number of generations to simulate
N=np.zeros(manygens+1) #how many children in each generation
howmany = [2]
G=nx.Graph()
count = 0
G.add_node(1, gen = count) #gen 0
manynodes = 1 #how many nodes we currently have on the graph
N[count] = 1 #one child in gen 0
for g in range(manygens): #run through generations
thisgen = 0 #counter for infections this generation
for node, gen in nx.get_node_attributes(G, "gen").items():
if gen == g:
y = scipy.stats.poisson.rvs(mu=r, size=1) #see how many are infected
if y < 1: #if less than 1 person is infected (no more reproduction from)
break
else:
reset = 0
while y >= 1:
G.add_node(manynodes + 1, gen = count + 1) #add the infected node
G.add_edge(node, manynodes + 1) #connect to parent
manynodes = manynodes + 1 #increase node counter
y = y - 1 #each node we add take away 1 from y
thisgen = thisgen + 1
count = count + 1
howmany.append(thisgen)
#nx.draw_spring(G) turn this on to show the graph
howmany.pop(-1)
#print(howmany)
return howmany