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

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!