How to create a histogram using numpy

Crystal X
2 min readJul 18, 2024

I was studying grouped and ungrouped data the other day and I discovered that numpy has a histogram function, which I had not previously been aware of.

A histogram is used to determine the frequency of which numbers show up the most in data by sorting groups into bins of the same size.

Numpy’s histogram() function works like matplotlib’s hist() function. Numpy’s histogram() provides the actual values of the frequency of the numbers that show up in data, but matplotlib’s hist() function visualises the pattern of numbers.

Numpy’s histogram() function shows how often different data values appear in a graph. The height of each rectangle drawn in a histogram shows how something usually occurs in a specific range, or bin.

The Python code below utilises numpy’s histogram() function. The histogram measures the height of a person and the bins have been set to auto:-

The Python code below utilises matplotlib’s hist() function. It also represents the height of a person and the bins are again set to auto. As can be seen, the difference between numpy’s histogram() function and matplotlib’s hist() function is the fact that…

--

--

Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.