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 Stacked Step histogram (unfilled) using Python’s Matplotlib library

In my previous posts, we have seen how we can plot stacked histogram (filled) and a stacked bar graph. In this post, we will see how we can plot a stacked Step histogram (unfilled) using Python’s Matplotlib library.

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). In a histogram, rectangles with equal sizes in the horizontal directions have heights with the corresponding frequencies.

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 Stacked Step histogram (unfilled) using Python’s Matplotlib library:

The below code will create the stacked step histogram (unfilled) using Python’s Matplotlib library. To plot, we have to pass the parameter stacked = True in the plt.hist() which informs Matplotlib library to perform the stacking task and we have to pass fill=False so that it can be shown unfilled in a form of steps. Have a look at the below code:

n_bins=30
x = np.random.randn(1000, 3)
colors = ['blue', 'orange', 'green']
plt.hist(x, n_bins, histtype='step', stacked=True, fill=False, label=colors)
plt.legend(loc="upper right")
plt.title('Stack Step (unfilled)')
plt.show()

Plotting Stacked Step histogram (unfilled)

 

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

Related posts:

  1. Plotting stacked histogram using Python’s Matplotlib library
  2. Plotting stacked bar graph using Python’s Matplotlib library
  3. Plotting multiple bar graph using Python’s Matplotlib library
  4. Plotting multiple histograms with different length using Python’s Matplotlib library

Filed Under: Data Analytics, Python Tagged With: Data Analysis, Matplotlib, 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.