我有一个分布,我希望集成了通过对分布的情节用户的鼠标点击选择一个自定义的范围。
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from scipy.integrate import trapz
# Probability Density Function
pdf = stats.norm.pdf
#adjust the location and scale of the distribution
loc1, scale1, size1 = (20, 1.5, 500)
loc2, scale2, size2 = (28, 2.5, 500)
# Probability Density Function
pdf = stats.norm.pdf
x2 = np.concatenate([np.random.normal(loc=loc1, scale=scale1, size=size1),np.random.normal(loc=loc2, scale=scale2, size=size2)])
x_eval = np.linspace(x2.min() - 1, x2.max() + 1, 1000)
bimodal_pdf = pdf(x_eval, loc=loc1, scale=scale1) * float(size1) / x2.size + pdf(x_eval, loc=loc2, scale=scale2) * float(size2) / x2.size
plt.figure()
plt.plot(x_eval,bimodal_pdf)
plt.show()
在这一点上,我想能够选择x的下限和上限在其中Y积分将被计算。
即。
a = User mouse click x position 1
b = User mouse click x position 2
area = trapz(y[a,b], x[a:b])
print 'the area under curve between x1 and x2 = ' + str(area)