Creating Histogram with Pyplot
A Histogram is a graphical display of data using bars of different heights. In a
histogram, each bar groups number into ranges. The highest or tallest bars show
that more data falls in that range of values(called bins). We use hist() function for
generating histogram in Pyplot.
Difference between bar chart and Histogram:
Bar chart represents a single value whereas histogram represents range of value.
It is similar to bar graph but it doesn’t show gaps between the bars.
Syntax:
[Link](x, bins=None, cumulative=False, histtype= ‘bar’, align= ‘mid’,
orientation= “vertical”)
Here,
x array or sequence to be plotted on histogram
bins it is optional. If an integer is given it automatically divides the number of
ranges (i.e. if bins=4, the whole list will be divided into for 4 ranges). We
can also define the sequence in bins also.
Cumulative it is optional. It takes Boolean value i.e. True or False. If it is True, then
a histogram, is computed where each bin gives the counts in that bin plus
all bins for smaller values. The last bin gives the total number of data
points.
histtype it is optional. It has following types: {bar, barstacked, step, stepfilled}. By
default the value is bar.
Orientation: it is optional. It has two values i.e. horizontal and vertical.
Example1:
import [Link] as pl
a=[2,3,7,19,6,8,11,14,15,22,33,24,22,8,2,4]
[Link](a)
[Link]()
import [Link] as pl
a=[2,3,7,6,8,12,4]
[Link](a)
[Link]()
Defining Range using bins:
import [Link] as pl
a=[2,3,7,6,8,12,4]
[Link](a,bins=[1,5,10,15])
[Link]()
import [Link] as pl
a=[2,3,7,6,8,12,4]
[Link](a,bins=[1,10,20])
[Link]()