This is our sixth article in Python Matplotlib, in this article we are going to learn about Matplotlib Plotting Histogram, a histogram is an approximate representation of the distribution of numerical or categorical data. It was first introduced by Karl Pearson. in fact, a Histogram is just a specific kind of bar chart. we could easily use Maplotlib’s bar chart function and do some statistics to generate Histograms. However, histograms are so useful that matplotlib provides a function just for them.
Matplotlib Tutorials For Beginners
1: Matplotlib Introduction & Installation
2: Matplotlib Plotting Multiple Curves
3: Matplotlib Plotting Scatter (Points)
4: Matplotlib Plotting BarChart
5: Matplotlib Plotting PieChart
OK now let’s create our example, the following code draws 500 values from a normal distribution and then generates histograms with 10 bins.
1 2 3 4 5 6 7 8 |
import numpy as np import matplotlib.pyplot as plt X = np.random.randn(500) plt.hist(X, bins = 10) plt.show() |
So in the above code the plt.hist() function takes a list of values as input, the range of the values will be divided
int to equal-sized bins. The plt.hist() function will generate a bar chart, one bar for one bin. The number of bins is determined by the optional parameter bins. By setting the optional parameter normed to True, the bar height is normalized and the sum of all bar heights is equal to 1.
So now if you run the complete code this will be the result
Subscribe and Get Free Video Courses & Articles in your Email