- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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 −
- Related Articles
- How is the Pyplot histogram bins interpreted? (Matplotlib)
- Getting information for bins in Matplotlib histogram function
- How to make a histogram from a list of data in Matplotlib?
- How to have logarithmic bins in a Python histogram?
- 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 plot a histogram using Matplotlib in Python with a list of data?
- How to plot a 2D histogram in Matplotlib?
- How to make a log histogram in Python?
- How to plot hexbin histogram in Matplotlib?
- How to center labels in a Matplotlib histogram plot?
- How to deal with warning message `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. in R while creating a histogram?
- How to get a reverse-order cumulative histogram in Matplotlib?
- Histogram for discrete values with Matplotlib
- Matplotlib histogram with multiple legend entries