Let’s see how to create histogram in Matplotlib and Numpy Python libraries the easiest way.
To create histogram in Python the easiest way it is enough you will import Matplotlib and Numpy Python libraries. They have all nesesery functions built-in.
We will insert histogram based on randomly generated numbers using below Python code.
import numpy as np from matplotlib import pyplot as plt histogram = np.random.randn(1000000) plt.hist(histogram, bins=2000) plt.title("Histogram by Pythoneo.com") plt.show()
Numpy randn function will help you to generate random numbers needed for histogram. The higher number the more detailed histogram. Python does not have any problems in generating even one million of numbers in a few seconds.
Hist function will generate a histogram based on generated numbers. The more bins you will choose the more detailed histogram you will get. Remember that number of bins must be much lower than generated numbers.