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!

采纳的回答

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 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by