Bar chart vs histogram

Bar chart vs histogram

Instructor-svg Al-Mamun Sarkar
Apr 02 , 2020

Bar chart vs histogram - Pyplot of Mathplotlib module. The following codes shows the difference between Bar chart and Histogram using pyplot of python mathplotlib module.

 

Import Module:

import matplotlib.pyplot as plt

 

Create data and plot bar chart:

population_ages = [22,55,62,45,21,22,34,42,42,4,99,102,110,120,121,122,130,111,115,112,80,75,65,54,44,43,42,48]
ids = [x for x in range(len(population_ages))]
plt.bar(ids, population_ages, label="Bar")
plt.title("Welcome to bar chart ploting tutorial \n This is Another Line")
plt.xlabel('X-Axis')
plt.ylabel('Y-Axis')
plt.legend()
plt.show()

 

Create data and plot histogram chart:

population_ages = [22,55,62,45,21,22,34,42,42,4,99,102,110,120,121,122,130,111,115,112,80,75,65,54,44,43,42,48]
bins = [0,10,20,30,40,50,60,70,80,90,100,110,120,130]

plt.hist(population_ages, bins, histtype='bar', rwidth=0.8, label='Test Histogram')

plt.title("Welcome to histograms ploting tutorial \n This is Another Line")
plt.xlabel('X-Axis')
plt.ylabel('Y-Axis')
plt.legend()
plt.show()

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram