In: Computer Science
Use Python to plot poisson process for time interval [0,50] that generate 50 random numbers.
CODE :
One can obtain different graphs by simply changing the lamda variable in the above code. To display the coordinates on the graph, please remove the commenting hastags in line 16 and 17 (the graph may look messed up).
Code you can directly copy and paste :
import matplotlib.pyplot as plt
import math
import numpy as np
x = np.arange(1,51,1) # time interval in format of start+1 to end+1 to get the range as [start,end]
p = [] # list to contain the poisson process calculated value
lamda = 10 # lamda is the mean of events per interval
for y in x:
f = pow(lamda,y)*math.exp(-1*lamda)/math.factorial(y) # formula of poisson's distribution
p.append(f)
plt.plot(x,p,marker='o', markerfacecolor='red', markersize=5)
#for i_x, i_y in zip(x, p): # marking co-ordinates on the graph
# plt.text(i_x, i_y, '({}, {})'.format(i_x, round(i_y,3)))
plt.xlabel('time') # naming the x axis
plt.ylabel('number') # naming the y axis
plot_title = 'Poisson Process Graph for lambda = ' + str(lamda) # giving a title to the graph
plt.title(plot_title)
plt.xlim(0,51)
plt.show()
NOTE : Indent this code by referring to the above code snapshot.
OUTPUT GRAPH: