Python ProgrammingPython Programming

Plot two histograms at the same time with Matplotlib

Plot multiple histograms

import numpy as np
import matplotlib.pyplot as plt

age = np.random.normal(loc=1, size=100) # a normal distribution
salaray = np.random.normal(loc=-1, size=10000) # a normal distribution

_, bins, _ = plt.hist(age, bins=50, range=[-6, 6], density=True)
_ = plt.hist(salaray, bins=bins, alpha=0.5, density=True)
plt.show()

The following is the output that will be obtained:


Plot multiple histograms