13.3 Histograms
A histogram is a form of bar chart for displaying statistical data. In Figure 5.12 in section 5.7.2, I showed a plot of one million random numbers in a normal distribution with mean μ = 1.0 and standard deviation σ = 0.2. This code creates a histogram with the same characteristics:
import matplotlib.pyplot as plt
import numpy as np
plt.clf()
np.random.seed(23)
# generate the random numbers in a normal distribution
mu = 1.0
sigma = 0.2
random_numbers = np.random.normal(mu, sigma, 1000000)
# set the number of bins in which to divide up the random numbers
bin_size = 100
# draw the histogram
the_plot = plt.hist(random_numbers, bins=bin_size)
<Figure size 432x288 with 1 Axes>
plt.show()
The bins
argument determines how many bars are in the
histogram.
Exercise 13.13
Does decreasing bin_size
make the histogram smoother or
blockier?
...