How to move forward the shaded area in MATLAB plot?

조회 수: 1 (최근 30일)
Armando MAROZZI
Armando MAROZZI 2021년 3월 24일
답변: Ananya Tewari 2021년 3월 31일
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!

채택된 답변

Ananya Tewari
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개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by