Simple Histogram
Simple Histogram/Sampling from normal distribution
This is a really simple example of a histogram in MatPlotLib, using a random sample from a normal distribution with np.random.normal
.
from matplotlib import pyplot as plt
import numpy as np
The function np.random.normal
takes many arguments, but the most important ones are loc
, scale
, and size
.
Parameter | Function |
---|---|
loc |
determines the mean (\mu) of the normal distribution from which the sample is taken |
scale |
determines the standard deviation (\sigma of the normal distribution from which the sample is taken |
size |
the number of samples to draw |
N = 10_000
data = np.random.normal(loc=250, scale=100, size=N)
The plt.hist()
function takes in one positional argument for data.
An important keyword argument is the bins
argument, which determines how many bins the histogram is split into.
plt.hist(data, bins=30)