如何在八度音阶下的函数下阴影区域?

noP*_*PEx 2 numpy graph octave scipy

我想展示阈值对FAR和FRR(基本上是x范围有界时曲线下的区域)的影响。为此,我需要做这样的事情!

图冒名顶主vs真实尝试

如果阈值移动,则由端部和阈值界定的相应区域也将移动。我还希望两个相应的区域具有不同的颜色。有没有办法在octave / python /任何其他工具中做到这一点。最简单的方法是什么?

还有教科书作者如何绘制此类图形。这些肯定不是标准功能。

tia*_*ago 5

在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)

distributions_yellow

如果只需要图形的底部(即阈值前后的功能区),这也很容易。让我们将图中的阈值定义为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)

distributions_small


car*_*aug 5

这在 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)