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 (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap