Skip to content

Instantly share code, notes, and snippets.

@charlesreid1
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesreid1/041fcab50d69fbe4b203 to your computer and use it in GitHub Desktop.
Save charlesreid1/041fcab50d69fbe4b203 to your computer and use it in GitHub Desktop.
Compute Empirical CDF in Matplotlib
import numpy as np
import seaborn as sns
import matplotlib.pylab as plt
from numpy.random import weibull
from scipy.stats import cumfreq
Nsamples = 5000
Nsamples_new = 500
# generate a weibull distribution
k=5
z = weibull(k,(Nsamples,))
# useful function
def find_nearest_index(vec,val):
ix = (np.abs(vec-val)).argmin()
return ix
# nice trick for getting the empirical cdf:
# http://stackoverflow.com/questions/3209362/how-to-plot-empirical-cdf-in-matplotlib-in-python
zsrt = np.sort(z)
cdf = np.arange(len(zsrt))/float(len(zsrt))
normed = np.array([ cdf[find_nearest_index(zsrt,zz)] for zz in z])
print normed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment