VOOZH about

URL: https://www.geeksforgeeks.org/data-visualization/how-to-plot-two-histograms-together-in-matplotlib/

⇱ How to plot two histograms together in Matplotlib? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to plot two histograms together in Matplotlib?

Last Updated : 23 Jul, 2025

Creating the histogram provides the visual representation of data distribution. By using a histogram we can represent a large amount of data and its frequency as one continuous plot. 

How to plot a histogram using Matplotlib

For creating the Histogram in Matplotlib we use hist() function which belongs to pyplot module. For plotting two histograms together, we have to use hist() function separately with two datasets by giving some settings. 

Syntax of matplotlib.pyplot.hist

matplotlib.pyplot.hist(x, bins, edgecolor color, label)

Example 1:

Here, we are simply taking two series using the Numpy random and passing both series to the hist()function, and we're using the same plot to plot two histograms together.

Output:

👁 plot two histograms together in Matplotlib
 

Example 2:

Here, we are using label, edgecolor, and opacity.

Output:

👁 plot two histograms
 

Example 3: 

Histograms represent two age groups using given data.

Output:

👁 plot two histograms
 

Example 4

Changing bar color from the default

Output:

👁 plot two histograms together
 
Comment