Two time series plots and shading between them…MATLAB

有些话、适合烂在心里 提交于 2019-12-06 13:29:06

As @Jonas explained (beat me to it), you need to properly order the data of the two time-series. Let me add an example to that:

%# first series
x1 = linspace(pi/4, 5*pi/4, 100);
y1 = cos(x1);

%# second series
x2 = linspace(pi/4, 5*pi/4, 100);
y2 = sin(x2);

subplot(121), fill([x1 x2], [y1 y2], 'r')
subplot(122), fill([x1 fliplr(x2)], [y1 fliplr(y2)], 'r')
hold on
plot(x1,y1, 'Color','b', 'LineWidth',3)
plot(x2,y2, 'Color','g', 'LineWidth',3)

I guess that you create the fill with

fill([xData1;xData2],[yData1;yData2])

where xData1 is a n-by-1 array of x-data for your first curve. This will lead to a weirdly-shaped polygon because the 'corners' of the polygon are not properly ordered.

Instead, you should do

fill([xData1;xData2(end:-1:1)],[yData1;yData2(end:-1:1])

i.e. flip the order of one of the two data sets.

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