>>> import matplotlib.pyplot as plt >>> count, bins, ignored = plt.hist(s, 30, density=True) >>> plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * ... np.exp( - (bins - mu)**2 / (2 * sigma**2) ), ... linewidth=2, color='r') >>> plt.show()
Here is what the above code is Doing:
1. We’re creating a random sample of data from a normal distribution.
2. We’re plotting a histogram of the data.
3. We’re plotting a normal distribution curve on top of the histogram.
The normal distribution curve is a good fit for the data.
Now let’s look at a sample of data that is not from a normal distribution.