- 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
Setting a relative frequency in a Matplotlib histogram
63 Lectures 6 hours
To set a relative frequency in a matplotlib histogram, we can take the following steps −
Create a list of numbers for data and bins.
Compute the histogram of a set of data, using histogram() method.
Get the hist and edges from the histogram.
Find the frequency of the histogram.
Make a bar with bins (step 1) and freq data (step 4).
To display the figure, use show() method.
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True a = [-0.125, .15, 8.75, 72.5, -44.245, 88.45] bins = np.arange(-180, 181, 20) hist, edges = np.histogram(a, bins) freq = hist/float(hist.sum()) plt.bar(bins[:-1], freq, width=20, align="edge", ec="k", color='red') plt.show()
- How to create histogram with relative frequency in R?
- Matplotlib – Make a Frequency histogram from a list with tuple elements in Python
- Absolute and Relative frequency in Pandas
- How to plot a 2D histogram in Matplotlib?
- Plotting a histogram from pre-counted data in Matplotlib
- How to center labels in a Matplotlib histogram plot?
- Python - Plot a Histogram for Pandas Dataframe with Matplotlib?
- Plot a histogram with Y-axis as percentage in Matplotlib
- Plotting a transparent histogram with non-transparent edge in Matplotlib
- Plot a histogram with colors taken from colormap in Matplotlib
- How to get a reverse-order cumulative histogram in Matplotlib?
- How to make a histogram from a list of data in Matplotlib?
- Setting the aspect ratio of a 3D plot in Matplotlib
- Setting the limits on a colorbar of a contour plot in Matplotlib
- Vertical Histogram in Python and Matplotlib