WeirdGeek

Data Science | Machine Learning | Automation

  • Data Analytics
  • Python
  • Data Science
  • Google Apps Script
  • Machine Learning
  • Artificial Intelligence
  • SQL Server

24/11/2018 By WeirdGeek Leave a Comment

Plotting multiple histograms with different length using Python’s Matplotlib library

In my previous posts, we have seen how we can plot stacked histogram (filled) and a stacked Step histogram (unfilled). In this post, we will see how we can plot multiple histograms with different length using Python’s Matplotlib library on the same axis.

Basically, Histograms are a graphical representation of a frequency distribution of numerical data and it’s a great visualizing tool for quickly assessing a probability distribution of a continuous variable (quantitative variable). Here we have three values in an array and we will plot three different coloured histograms on the same axis.

First of all, to create any type of histogram whether it’s a simple histogram or a stacked histogram, we need to import libraries that will help us to implement our task.

Below are the two libraries Numpy and Matplotlib which helps us to perform our task:

import numpy as np
from Matplotlib.pyplot as plt
Let’s plot multiple histograms with different length using Python’s Matplotlib library:

The below code will create the stacked step histogram (unfilled) using Python’s Matplotlib library. To plot, we have created an array with three values [] and then passed the array into np.random.randn() using for loop so that Matplotlib library can plot multiple histograms with different length on the same axis. Have a look at the below code:

n_bins=30
colors = ['blue', 'orange', 'green']
# Make a multiple-histogram of array of three values with different length.
array = [10000, 5000, 2000]
x_multi = [np.random.randn(n) for n in array ]
plt.hist(x_multi, n_bins, histtype='bar', label=colors)
plt.legend(loc="upper right")
plt.title('Different Sample Sizes')
plt.show()

Plotting a multiple histogram with different length

 

Hope you like our post. To learn more about Matplotlib package, you can go through the official documentation here.

Related posts:

  1. Plotting multiple bar graph using Python’s Matplotlib library
  2. Plotting stacked bar graph using Python’s Matplotlib library
  3. Plotting stacked histogram using Python’s Matplotlib library
  4. Plotting Stacked Step histogram (unfilled) using Python’s Matplotlib library

Filed Under: Data Analytics, Python Tagged With: Histogram, Matplotlib, Multiple Histogram, Python

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Subscribe to my Blog !!

Enter your email below to subscribe my blog and get the latest post right in your inbox.

  • Home
  • Terms
  • Privacy
  • Contact Us

Copyright © 2025 · WeirdGeek · All trademarks mentioned are the property of their respective owners.