- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to make a histogram with bins of equal area in Matplotlib?
To make a histogram with bins of equal area in matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create random data points using numpy.
Plot a histogram with equal_area method that makes an equal area of the patches.
To display the figure, use show() method.
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def equal_area(x, nbin): pow = 0.5 dx = np.diff(np.sort(x)) tmp = np.cumsum(dx ** pow) tmp = np.pad(tmp, (1, 0), 'constant') return np.interp(np.linspace(0, tmp.max(), nbin + 1), tmp, np.sort(x)) x = np.random.randn(1000) n, bins, patches = plt.hist(x, equal_area(x, 20), edgecolor='black') plt.show()
It will produce the following output −
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- Getting information for bins in Matplotlib histogram function
- How to have logarithmic bins in a Python histogram?
- How to make a histogram from a list of data in Matplotlib?
- How to create a histogram without bins in base R?
- Matplotlib – Make a Frequency histogram from a list with tuple elements in Python
- How to make a log histogram in Python?
- How to plot a histogram using Matplotlib in Python with a list of data?
- How to plot a 2D histogram in Matplotlib?
- Histogram for discrete values with Matplotlib
- Matplotlib histogram with multiple legend entries
- How to center labels in a Matplotlib histogram plot?
- How to plot hexbin histogram in Matplotlib?
- Program to make a histogram of an array in C++
- How to create a 100% stacked Area Chart with Matplotlib?