How to plot histogram in Matplotlib

You can plot the histogram in Matplotlib with the following code. If you want to learn Python then I will highly recommend you to read This Book.

How to plot histogram in Matplotlib
How to plot histogram in Matplotlib
x = [1,2,2,2,3,3,4,4,4,4,5,5,5,6,6,10,10,7,7,7,7,7,9,9,9]

plt.title("Histogram")
plt.xlabel("Numbers")
plt.ylabel("Frequency")

plt.hist(x)
plt.show()

You can increase or decrease the number of bins. By default is 10 in Matplotlib. You can also change the color of the histogram.

y = [1,2,2,2,3,3,4,4,4,4,5,5,5,6,6,10,10,7,7,7,7,7,9,9,9]

plt.title("Histogram")
plt.xlabel("Numbers")
plt.ylabel("Frequency")

plt.hist(y,bins=20,color='green')
plt.show()

People are also reading:

Best Python Books

What is Computer Vision? Examples, Applications, Techniques

Top 10 Computer Vision Books with Python

Books for Machine Learning (ML)

Free Learning Resources

Leave a Comment

Your email address will not be published.