1# fit an empirical cdf to a bimodal dataset
2from matplotlib import pyplot
3from numpy.random import normal
4from numpy import hstack
5from statsmodels.distributions.empirical_distribution import ECDF
6# generate a sample
7sample1 = normal(loc=20, scale=5, size=300)
8sample2 = normal(loc=40, scale=5, size=700)
9sample = hstack((sample1, sample2))
10# fit a cdf
11ecdf = ECDF(sample)
12# get cumulative probability for values
13print('P(x<20): %.3f' % ecdf(20))
14print('P(x<40): %.3f' % ecdf(40))
15print('P(x<60): %.3f' % ecdf(60))
16# plot the cdf
17pyplot.plot(ecdf.x, ecdf.y)
18pyplot.show()
19
1...
2# get cumulative probability for values
3print('P(x<20): %.3f' % ecdf(20))
4print('P(x<40): %.3f' % ecdf(40))
5print('P(x<60): %.3f' % ecdf(60))
6
1# example of a bimodal data sample
2from matplotlib import pyplot
3from numpy.random import normal
4from numpy import hstack
5# generate a sample
6sample1 = normal(loc=20, scale=5, size=300)
7sample2 = normal(loc=40, scale=5, size=700)
8sample = hstack((sample1, sample2))
9# plot the histogram
10pyplot.hist(sample, bins=50)
11pyplot.show()
12