NumPy Tutorial
NumPy Useful Resources
Selected Reading
- NumPy - I/O with NumPy
- NumPy - Histogram Using Matplotlib
- NumPy - Matplotlib
- NumPy - Linear Algebra
- NumPy - Matrix Library
- NumPy - Copies & Views
- NumPy - Byte Swapping
- Sort, Search & Counting Functions
- NumPy - Statistical Functions
- NumPy - Arithmetic Operations
- NumPy - Mathematical Functions
- NumPy - String Functions
- NumPy - Binary Operators
- NumPy - Array Manipulation
- NumPy - Iterating Over Array
- NumPy - Broadcasting
- NumPy - Advanced Indexing
- NumPy - Indexing & Slicing
- Array From Numerical Ranges
- NumPy - Array from Existing Data
- NumPy - Array Creation Routines
- NumPy - Array Attributes
- NumPy - Data Types
- NumPy - Ndarray Object
- NumPy - Environment
- NumPy - Introduction
- NumPy - Home
NumPy Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
NumPy - Histogram Using Matplotlib
NumPy - Histogram Using Matplotpb
NumPy has a numpy.histogram() function that is a graphical representation of the frequency distribution of data. Rectangles of equal horizontal size corresponding to class interval called bin and variable height corresponding to frequency.
numpy.histogram()
The numpy.histogram() function takes the input array and bins as two parameters. The successive elements in bin array act as the boundary of each bin.
import numpy as np a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27]) np.histogram(a,bins = [0,20,40,60,80,100]) hist,bins = np.histogram(a,bins = [0,20,40,60,80,100]) print hist print bins
It will produce the following output −
[3 4 5 2 1] [0 20 40 60 80 100]
plt()
Matplotpb can convert this numeric representation of histogram into a graph. The plt() function of pyplot submodule takes the array containing the data and bin array as parameters and converts into a histogram.
from matplotpb import pyplot as plt import numpy as np a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27]) plt.hist(a, bins = [0,20,40,60,80,100]) plt.title("histogram") plt.show()
It should produce the following output −
Advertisements