Mark As Completed Discussion

Histogram

The histogram is used where the data is been distributed while the bar graph is used in comparing the two entities. Histograms are preferred during the arrays or data containing the long list. Consider an example where we can plot the age of the population with respect to the bin. The bin refers to the range of values divided into a series of intervals. In the below example bins are created with an interval of 10 which contains the elements from 0 to 9, then 10 to 19, and so on.

PYTHON
1population_age = [22,55,62,45,21,22,34,42,42,4,2,102,95,85,55,110,120,70,65,55,111,115,80,75,65,54,44,43,42,48]
2bins = [0,10,20,30,40,50,60,70,80,90,100]
3
4fig = plt.figure()
5ax = fig.add_axes([0,0,1,1]) # [x0, y0, width, height]
6ax.hist(population_age,bins=bins, rwidth=0.8)
7ax.legend(labels=['Population'])
8fig.show()
9
10px.histogram(x=population_age, nbins=11)

Histogram