A histogram is the best way to visualize the frequency distribution of a dataset by splitting it into small equal-sized intervals called bins. The Numpy histogram function is similar to the
hist() function of matplotlib library, the only difference is that the Numpy histogram gives the numerical representation of the dataset while the
hist() gives graphical representation of the dataset.
Creating Numpy Histogram
Numpy has a built-in
numpy.histogram() function which represents the frequency of data distribution in the graphical form. The rectangles having equal horizontal size corresponds to class interval called bin and variable height corresponding to the frequency.
numpy.histogram(data, bins=10, range=None, normed=None, weights=None, density=None)
Attributes of the above function are listed below:
|data||array or aequence of array to be plotted|
|bins||int or sequence of str defines number of equal width bins in a range, default is 10|
|range||optional parameter sets lower and upper range of bins|
|normed||optional parameter same as density attribute, gives incorrect result for unequal bin width|
|weights||optional parameter defines array of weights having same dimensions as data|
|density||optional parameter if False result contain number of sample in each bin, if True result contain probability density function at bin|
The function has two return values hist which gives the array of values of the histogram, and edge_bin which is an array of float datatype containing the bin edges having length one more than the hist.
The above numeric representation of histogram can be converted into a graphical form.The
plt() function present in
pyplot submodule of Matplotlib takes the array of dataset and array of bin as parameter and creates a histogram of the corresponding data values.
- class method vs static method in Python
- Difference between Method Overloading and Method Overriding in Python
- Get() method for dictionaries in Python
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Python Program to detect the edges of an image using OpenCV | Sobel edge detection method
- Line detection in python with OpenCV | Houghline method
- Python | os._exit() method
- Python | os.WEXITSTATUS() method
- Python | os.abort() method
- Python | os.renames() method
- Python | os.lseek() method
- Python calendar module | formatmonth() method
- Python | PyTorch sin() method
- Python | Sympy Line.is_parallel() method
- Python PIL | GaussianBlur() method
- Python | range() method
- Python | Numpy np.hermefit() method
- Python | Numpy np.hermevander() method
- Python String Title method
- Python groupby method to remove all consecutive duplicates
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.