- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
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 plot cdf in Matplotlib in Python?
To plot cdf in matplotlib in Python, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Initialize a variable N for the number of sample data.
Create random data using numpy.
Compute the histogram of a set of data with data and bins=10.
Find the probability distribution function (pdf).
Using pdf (Step 5), calculate cdf.
Plot the cdf using plot() method with label "CDF".
Place a legend on the plot.
To display the figure, use show() method.
Example
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True N = 500 data = np.random.randn(N) count, bins_count = np.histogram(data, bins=10) pdf = count / sum(count) cdf = np.cumsum(pdf) plt.plot(bins_count[1:], cdf, label="CDF") plt.legend() plt.show()
Output
- Related Articles
- How to a plot stem plot in Matplotlib Python?
- How to plot signal in Matplotlib in Python?
- How to plot MFCC in Python using Matplotlib?
- How to plot vectors in Python using Matplotlib?
- How to plot magnitude spectrum in Matplotlib in Python?
- How to plot an array in Python using Matplotlib?
- How to plot a density map in Python Matplotlib?
- How to plot a multivariate function in Python Matplotlib?
- How to plot a layered image in Matplotlib in Python?
- How to plot a phase spectrum in Matplotlib in Python?
- How To Annotate Bars in Bar Plot with Matplotlib in Python?
- How to save a plot in Seaborn with Python (Matplotlib)?
- How to plot longitudinal magnitude spectrum in Matplotlib using Python?
- How to plot an angle spectrum using Matplotlib in Python?
- How to plot an area in a Pandas dataframe in Matplotlib Python?

Advertisements