How to reshape the x-axis in this case?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!