Matplotlib Histograms 📶
Frequency Distributions
A histogram shows the frequency distribution of a dataset. It groups data into "bins" and counts how many values fall into each bin.
✨ Creating a Histogram
Use the hist() function. We'll generate random data using NumPy for this example.
python
import matplotlib.pyplot as plt
import numpy as np
# Generate 250 random values around 170 with std dev 10
x = np.random.normal(170, 10, 250)
plt.hist(x)
plt.show()💡 Bins
You can control the number of intervals using the bins parameter. More bins = more detail.
python
plt.hist(x, bins=20)