Figure 4.8:

Histogram of 10,000 samples of uniformly distributed x.

Code for Figure 4.8

Text of the GNU GPL.

main.py


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import numpy as np
import matplotlib.pyplot as plt

nsam = 10000
nsum = 10
x = np.random.rand(nsum, nsam)
y = np.sum(x, axis=0)

nbins = 20

plt.figure()
plt.hist(y, bins=nbins)
plt.show(block=False)

plt.figure()
plt.hist(x[0, :], bins=nbins)
plt.show(block=False)

nx, binsx = np.histogram(x[0, :], bins=nbins)
# make bar plot data for gnuplot
barx1 = np.kron(binsx,[1,1,1])[1:-1]
bary1 = np.append(np.kron(nx, [0, 1, 1]), 0)

ny, binsy = np.histogram(y, bins=nbins)
# make bar plot data for gnuplot
barx2 = np.kron(binsy,[1,1,1])[1:-1]
bary2 = np.append(np.kron(ny, [0, 1, 1]), 0)

data = np.column_stack( (barx2, bary2, barx1, bary1) )

# Save the data to 'cenlim.dat'
with open("cenlim.dat", "w") as f:
    np.savetxt(f, data, fmt='%f', header="data")