How to move forward the shaded area in MATLAB plot?
조회 수: 2 (최근 30일)
이전 댓글 표시
I need to plot a graph where the first line is from, say, 2006-2008, and the second one from 2008-2009. The latter one has confidence interval which I plot as shaded area but the result is the one you see in the plot attached. How can I get the shaded area to move forward and align with the solid red line?
The code I have is the following:
x = (1:size(forecast,1)).';
plot(t(t >= '01-Jan-2006' & t < '01-Jan-2008'),movmean(dep_b,30),'-k',t(t >= '01-Jan-2008' & t <= '02-Nov-2009'), movmean(forecast(1:length(forecast)),30),'-r')
hold on
patch([x; flipud(x)], [movmean(forecast(:,3),30); flipud(movmean(forecast(:,2),30))], [1,0,0], 'FaceAlpha', .1, 'EdgeColor', 'none');
hold on
xline(t(t == '01-Jan-2008'), '-b')
legend('Actual', 'Forecast', 'Orientation', 'horizontal', 'Location', 'southoutside')
box on;
How can I modify it to shift the shaded area forward?
Thanks a lot!
댓글 수: 0
채택된 답변
Ananya Tewari
2021년 3월 31일
I understand you want to shift the shaded area forward and align it with the forecasted plot. Applying the offset in the x-coordinates of the patch() can help get the dersired result. The offset should be following the unit of x
patch([x+offset; flipud(x)+offset], [movmean(forecast(:,3),30); flipud(movmean(forecast(:,2),30))], [1,0,0], 'FaceAlpha', .1, 'EdgeColor', 'none');
댓글 수: 0
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!