In [4]:
import random # load the module
In [6]:
r = random.random() # equally distributed random number
print("Random 0 <= r == {} < 1".format(r))
In [7]:
μ = 200
σ = 25
g = random.gauss(μ, σ)
print("Gauss distributed random number {} with μ={} and σ={}".format(g, μ, σ))
Import numpy
In [8]:
import numpy as np
np.random.seed(0)
Generate random numbers.
In [49]:
normal_numbers = np.random.normal(μ, σ, size=100)
print("normal_numbers = {}".format(normal_numbers))
Install plotly from the command line:
We generate a plot
In [53]:
import numpy as np
import matplotlib.pyplot as plt
fig, (ax0, ax1) = plt.subplots(ncols=2, figsize=(8, 4))
ax0.hist(normal_numbers, 20, normed=1, histtype='stepfilled', facecolor='g', alpha=0.75)
ax0.set_title('stepfilled')
# Create a histogram by providing the bin edges (unequally spaced).
bins = [100, 150, 180, 195, 205, 220, 250, 300]
ax1.hist(normal_numbers, bins, normed=1, histtype='bar', rwidth=0.8)
ax1.set_title('unequal bins')
fig.tight_layout()
plt.show()
In [ ]: