import numpy as np
import matplotlib.pyplot as plt
nsam = 11
np.random.seed(10)
p = np.random.rand(nsam, 1)
tau = -np.log(p)
time = np.cumsum(tau, axis=0)
time = np.insert(time, 0, 0, axis=0)
Y = np.arange(nsam + 1)
xx, yy = np.repeat(time, 2)[1:-1], np.repeat(Y, 2)[:-2] # Equivalent to stairs without the last element
plt.figure()
plt.plot(xx, yy)
plt.show(block=False)
plt.figure()
plt.hist(tau, bins=20)
plt.show(block=False)
table = np.column_stack((xx, yy))
with open("unitpoisson.dat", "w") as f:
np.savetxt(f, table, fmt='%f', header="time Y")