How to reshape the x-axis in this case?
4 views (last 30 days)
Show older comments
Armando MAROZZI
on 29 Oct 2020
Commented: Star Strider
on 29 Oct 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 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!