在python中,您可以使用matplotlib的fill_between:
import numpy as np
import matplotlib.pyplot as plt
# Create some fake data
x = np.arange(0, 20, 0.01)
y1 = np.exp(-(x - 6)**2 / 5.)
y2 = 2 * np.exp(-(x - 12)**2 / 8.)
plt.plot(x, y1, 'r-')
plt.plot(x, y2, 'g-')
plt.fill_between(x, 0, y1, color='r', alpha=0.6)
plt.fill_between(x, 0, y2, color='g', alpha=0.6)
Run Code Online (Sandbox Code Playgroud)

在此,alpha用于创建透明度并在相交区域中组合两种颜色。您也可以使用其他颜色为该区域着色:
idx_intsec = 828
plt.fill_between(x[:idx_intsec], 0, y2[:idx_intsec], color='y')
plt.fill_between(x[idx_intsec:], 0, y1[idx_intsec:], color='y')
Run Code Online (Sandbox Code Playgroud)

如果只需要图形的底部(即阈值前后的功能区),这也很容易。让我们将图中的阈值定义为x = 7:
thres = 7.
idx_thres = np.argmin(np.abs(x - thres))
plt.plot(x[:idx_thres], y2[:idx_thres], 'g-')
plt.plot(x[idx_thres:], y1[idx_thres:], 'r-')
plt.plot([thres, thres], [0, y1[idx_thres]], 'r-')
plt.fill_between(x[:idx_thres], y2[:idx_thres], color='g', alpha=0.6)
plt.fill_between(x[idx_thres:], y1[idx_thres:], color='r', alpha=0.6)
Run Code Online (Sandbox Code Playgroud)

这在 Octave 中实际上非常容易。对另一个示例使用相同的代码(转换为 Octave):
## create same fake data as other example
x = 0:0.1:20;
y1 = exp(-(x-6).**2 / 5);
y2 = 2 * exp(-(x-12).**2 / 8);
area (x, y1, "FaceColor", "blue");
hold on;
area (x, y2, "FaceColor", "red");
area (x, min ([y1; y2]), "FaceColor", "green");
hold off
Run Code Online (Sandbox Code Playgroud)
我得到下图
应该可以改变区域的透明度,FaceAlpha但显然还没有在 Octave 中实现(尽管有一天)。同时,您可以传递 RGB 值作为解决方法
area (x, y1, "FaceColor", [0.0 0.0 0.8]);
hold on;
area (x, y2, "FaceColor", [0.0 0.8 0.0]);
area (x, min ([y1; y2]), "FaceColor", [0.0 0.8 0.8]);
hold off
Run Code Online (Sandbox Code Playgroud)