Tuesday, April 29, 2014

Plot CDF in Python

perhaps the most easy way of plotting the cumilative distribution function in python:


import numpy as np
import statsmodels.api as sm # recommended import according to the docs
import matplotlib.pyplot as plt

sample = np.random.uniform(0, 1, 50)
sample=[1,2,2,3,2,3,3,3,3,3,3,4,4,4,4,4,60,3,3,3,10]
ecdf = sm.distributions.ECDF(sample)

dsum = sum(sample);
normalized_data = sample/dsum;

x = np.linspace(min(sample), max(sample),10000)
print x
y = ecdf(x)
plt.step(x, y)

plt.show()


Here is the plot:



No comments:

Post a Comment