Highlight parts of matlab plot

六眼飞鱼酱① 提交于 2019-11-27 03:27:32

问题


I have a matlab plot that looks like this:

Where the Y values for each of the subplots are stored in single dimensional arrays. What i would like to do is to find an area where the top graph is above a certain height say 0.5. I would also like to highlight the same area in the other graphs as well.

Here is an example of what I am talking about:

The best i have been able to find so far is the function area which will fill an area on the matlab grid. However, if someone could tell me how to make it transparent and also how to fill multiple areas without having to do lots of area commands that would be great.

Otherwise I can identify a group of areas in a struct and use a for loop to plot them. Here is some psuedo code of the way i would do it:

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

Then to plot the areas i would do this:

for i = 1:length(areas)
    area(areas(i).outside, ones(length(area), 1)*14, "SomeThingToMakeItTransperant')
end

and i would do this for each of the subplots. Obviously this is quite convoluted so it would be better to have a one liner. Can anyone think of one?


回答1:


I figured it out, The psuedo code i provided gets the correct regions. You can then do this:

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 sets the transparency in most area plots. This in combination with the code in the question results in this:

This is pretty cool to plot in matlab.



来源:https://stackoverflow.com/questions/13734086/highlight-parts-of-matlab-plot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!