# How to reshape the x-axis in this case?

5 visualizaciones (últimos 30 días)
Armando MAROZZI el 29 de Oct. de 2020
Comentada: Star Strider el 29 de Oct. de 2020
I have a chart (attached) that starts the sample in 2008 despite the actual data starts in 2009-01. I would like to understand why and correct it.
This is an example that replicates the issue:
t1 = datetime(2009,01,01);
t2 = datetime(2019,11,01);
t = t1:calmonths:t2;
t= datenum(char(t),'dd-mm-yyyy');
subplot(3,1,1)
% 1st shaded area
d1=datenum(datetime(2009,01,01));
d2=datenum(datetime(2009,06,01));
x=[[d1,d2],[d2,d1],d1];
y=[-[6,6],[6,6],[-6]];
fill(x, y, [0.7 0.7 0.7],'LineStyle','none', 'FaceAlpha', 0.2);
hold on
% 2nd shaded area
d1=datenum(datetime(2011,09,01));
d2=datenum(datetime(2013,03,01));
x=[[d1,d2],[d2,d1],d1];
y=[-[6,6],[6,6],[-6]];
fill(x, y, [0.7 0.7 0.7],'LineStyle','none', 'FaceAlpha', 0.2);
hold on
plot(t, randn(131,1), 'LineWidth',1,'Color', [0 0 0]);
ax.XTick = t(1:end);
datetick('x','yyyy','keepticks');
yline(0,'-')
ylabel('%')
title('Business Cycle Shock', 'FontWeight', 'Normal')
subplot(3,1,2)
% 1st shaded area
d1=datenum(datetime(2009,01,01));
d2=datenum(datetime(2009,06,01));
x=[[d1,d2],[d2,d1],d1];
y=[-[6,6],[6,6],[-6]];
fill(x, y, [0.7 0.7 0.7],'LineStyle','none', 'FaceAlpha', 0.2);
hold on
% 2nd shaded area
d1=datenum(datetime(2011,09,01));
d2=datenum(datetime(2013,03,01));
x=[[d1,d2],[d2,d1],d1];
y=[-[6,6],[6,6],[-6]];
fill(x, y, [0.7 0.7 0.7],'LineStyle','none', 'FaceAlpha', 0.2);
hold on
plot(t, randn(131,1), 'LineWidth',1,'Color', [0 0 0]);
hold on
ax.XTick = t(1:end);
datetick('x','yyyy','keepticks');
yline(0,'-')
ylabel('%')
title('Monetary Policy Shock', 'FontWeight', 'Normal')
subplot(3,1,3)
% 1st shaded area
d1=datenum(datetime(2009,01,01));
d2=datenum(datetime(2009,06,01));
x=[[d1,d2],[d2,d1],d1];
y=[-[6,6],[6,6],[-6]];
fill(x, y, [0.7 0.7 0.7],'LineStyle','none', 'FaceAlpha', 0.2);
hold on
% 2nd shaded area
d1=datenum(datetime(2011,09,01));
d2=datenum(datetime(2013,03,01));
x=[[d1,d2],[d2,d1],d1];
y=[-[6,6],[6,6],[-6]];
fill(x, y, [0.7 0.7 0.7],'LineStyle','none', 'FaceAlpha', 0.2);
hold on
plot(t, randn(131,1), 'LineWidth',1,'Color', [0 0 0]);
hold on
ax.XTick = t(1:end);
datetick('x','yyyy','keepticks');
yline(0,'-')
ylabel('%')
title('DFPA Shock', 'FontWeight', 'Normal')
In other words, I would like the grey bar to start in 2009 when my sample starts and not before.
Can anyone help me?
Thanks.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Star Strider el 29 de Oct. de 2020
Either:
axis tight
or:
xlim([min(t) max(t)])
should work.
##### 2 comentariosMostrar NingunoOcultar Ninguno
Armando MAROZZI el 29 de Oct. de 2020
thanks!
Star Strider el 29 de Oct. de 2020
As always, my pleasure!

Iniciar sesión para comentar.

### Categorías

Más información sobre Axis Labels 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