Python: How to Plot a Histogram using Matplotlib and data as list


We can make use of the matplotlib.pyplot.hist() function from the Matplotlib in Python to plot a histogram.


Example:
import matplotlib.pyplot as pyplot

plotting_data = [3, 5, 2, 3, 2, 4, 3, 8, 9, 2, 5, 6, 4, 4, 3, 2, 1, 5, 8, 1, 7, 7, 8, 9]

pyplot.hist(plotting_data, bins=10, edgecolor='yellow')
pyplot.xlabel('Value')
pyplot.ylabel('Frequency of Number')
pyplot.title('Histogram using Matplotlib')
pyplot.show()

Histogram using Matplotlib

Documentation: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html

-

Facing issues? Have Questions? Post them here! I am happy to answer!


Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap