Joh*_*anC 10
np.amin您可以取4 条曲线中的最小值 ( ) 并计算其面积(例如通过np.trapz)。如果曲线没有公共 x,则首先需要使用共享 x 重新计算它们(例如使用np.interp)。
from matplotlib import pyplot as plt
from scipy.stats import gaussian_kde
import numpy as np
data = np.random.rand(6, 4) ** 3
x = np.linspace(-1, 2, 200)
ys = []
for label in range(4):
kde_func = gaussian_kde(data[:, label])
y = kde_func(x)
plt.plot(x, y, label=label)
ys.append(y)
y_intersection = np.amin(ys, axis=0)
area = np.trapz(y_intersection, x)
fill_poly = plt.fill_between(x, 0, y_intersection, fc='yellow', ec='black', alpha=0.5,
label=f'intersection: {area:.3f} ')
fill_poly.set_hatch('xxx')
plt.legend()
Run Code Online (Sandbox Code Playgroud)