# How to move forward the shaded area in MATLAB plot?

3 visualizaciones (últimos 30 días)
Armando MAROZZI el 24 de Mzo. de 2021
Respondida: Ananya Tewari el 31 de Mzo. de 2021
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 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Ananya Tewari el 31 de Mzo. de 2021
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 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by