This type of plot helps us to examine the distribution of numerical data in such a way that you are unable to make do with mean or median alone. We are going to use the hist() method to create a simple histogram. Let's look at an example to create a simple histogram. For that, create a script called histogram_example.py and write the following content in it:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.randn(500)
plt.hist(x)
plt.show()
Run the script and you will get the following output:
student@ubuntu:~/work$ python3 histogram_example.py
The output is as follows:
In the preceding example, we created an array of random numbers using numpy. Then we plotted that numerical data using the plt.hist() method.