Last active
August 29, 2015 14:19
-
-
Save charlesreid1/041fcab50d69fbe4b203 to your computer and use it in GitHub Desktop.
Compute Empirical CDF in Matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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