Python | Step Histogram Plot

Step Histogram Plot in Python. In this tutorial, we are going to learn about the step histogram plot and its Python implementation. By Anuj Singh Last updated : August 18, 2023

Step Histogram Plot

A histogram is a graphical technique or a type of data representation using bars of different heights such that each bar group's numbers into ranges (bins or buckets). Taller the bar higher the data falls in that bin. A Histogram is one of the most used techniques in data visualization and therefore, matplotlib has provided a function matplotlib.pyplot.hist() for plotting histograms. Step histogram is a type of histogram in which Bars are not filled with color, instead only the edge is the representation of Histogram. It is in a form of steps of stairs and therefore it is known as step histogram.

Example

The following example illustrates the implementation and use of the Step Histogram Plot.

Python | Step Histogram Plot (1) Python | Step Histogram Plot (2) Python | Step Histogram Plot (3)

Python program for step histogram plot

import matplotlib.pyplot as plt
import numpy as np

# random data generation
mu, sigma = 100, 15
x = mu + sigma * np.random.randn(10000)

# Histogram of the Data
plt.figure()
plt.hist(x, 25, histtype='step')
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Step Histogram')
plt.show()

plt.figure()
plt.hist(x, 15, density=1, histtype='step')
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Step Histogram : No. of Bins = 15')
plt.show()

plt.figure()
plt.hist(x, 10, density=1, edgecolor='purple', linewidth=2.0, histtype='step')
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Step Histogram : Edge Width = 2.0')
plt.show()

Output:

Output is as figure

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.