突出显示 Matlab 绘图的部分

9
我有一个Matlab图,看起来像这样: enter image description here 每个子图的Y值存储在单维数组中。我想找到一个区域,使得顶部图形高于某个高度,比如0.5。我还想在其他图表中突出显示相同的区域。
这是我所说的一个例子: enter image description here 到目前为止,我找到的最好的方法是使用area函数填充Matlab网格上的区域。但是,如果有人告诉我如何使它透明,并且如何填充多个区域而不必使用大量的area命令就好了。
否则,我可以标识一个结构中的一组区域并使用for循环将它们绘制出来。以下是我可能会使用的伪代码:
countstruct = 1;
for i = 1:length(yValue)
    if (yValue(i) > 1)
        outside = [outside, i]
    else
         areas(countstruct).outside = outside;
         countstruct = countstruct + 1;
         clear outside;

     end
 end

那么要绘制区域,我会这样做:
for i = 1:length(areas)
    area(areas(i).outside, ones(length(area), 1)*14, "SomeThingToMakeItTransperant')
end

我需要对每个子图都做这件事情。显然,这很复杂,最好有一个简单的方法。有人能想到吗?


你尝试过使用'patch()'函数吗? - jerad
谢谢@jerad,我之前没有想到,但现在我已经弄明白了。 - Fantastic Mr Fox
1个回答

4

我明白了,我提供的伪代码可以得到正确的区域。然后你可以这样做:

for i = 1:length(areas)
    harea = area(areas(i).outside, ones(length(areas(i).outside), 1)*14, 'LineStyle', 'none')
    set(harea, 'FaceColor', 'r')
    alpha(0.25)
    hold on
end

alpha参数在大多数区域图中用于设置透明度。与问题中的代码结合使用会产生以下结果:

在Matlab中绘制这样的图形非常酷。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接