How to Create Histogram in Python Matplotlib

In this Matplotlib tutorial we want to learn How to Create Histogram in Python Matplotlib, histograms are a powerful tool in data visualization, and it allows us to analyze the distribution and frequency of values within a dataset. Python Matplotlib library provides a simple and effective way to create histograms.



For creating histogram in matplotlib, we need to import the required modules.



For creating of histogram, we need to generate some random data using numpy random.randn() function. This will give us an array of random numbers with a normal distribution.



Using Matplotlib hist() function, we can create a histogram based on the generated data.



Matplotlib provides different customization options to enhance the appearance of the histogram. You can add labels, change colors, adjust the bin size and many more.



For displaying the histogram, we can use the function.



If you wish to save the histogram as an image, you can use the plt.savefig() function instead.



This is the complete code for this article




Run your code and this will be the output

How to Create Histogram in Python Matplotlib
How to Create Histogram in Python Matplotlib



Learn More on Python Matplotlib

Leave a Comment