IRFs plotting with standard error bands

Hi professor,
if I have a csv type file (ert.csv) which includes a matrix of 50*5 ( 50 periods and 5 variables) results of IRFs.

how am I supposed to modify the code below to plot each one ( 6 variables in total ) with their respective ONE UNIT STANDARD ERROR BANDS shown on the plots?

clear all; close all; clc;
load ert.csv

for i=1:6
subplot(2,3,i)
x = (1:size(ert,1))’;
y = mean(ert,2);
e = std(ert,1,2);

errorbar(x,y,e,‘rx’);
lo = y - e;
hi = y + e;

hp = patch([x; x(end:-1:1); x(1)], [lo; hi(end:-1:1); lo(1)], ‘r’);
hold on;
hl = line(x,y);

set(hp, ‘facecolor’, [1 0.8 0.8], ‘edgecolor’, ‘none’);
set(hl, ‘color’, ‘r’ );
axis tight;
set(gca,‘FontSize’,12, ‘FontName’,‘Times’)
ax = gca;
ax.YAxis.Exponent=0;
end

the desirable results are shown as the pic

That is not a Dynare question. And without the file to run the codes it is impossible to tell.

Thanks.m

Another question is:
when trying to adjust the color for the both sides of the Yaxis, it alwas failed to do so, instead it generated a new plot as shown below:

code I am using for the last subplot is:

subplot(2,3,6)
subplot = figure;
left_color = [0 0 1];
right_color = [1 0 1];
set(figure,'defaultAxesColorOrder',[left_color; right_color]);

yyaxis left
plot(ert(:,1),'b','LineWidth',2)
ylabel('pps')
hold on;
yyaxis right
plot(eprt_nocrisis(:,1),'m--','LineWidth',3)
title('3-month T-bills');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis(2).Exponent = 0;

How am I supposed to fix the problem?

Your are creating new figures when you call

subplot = figure;

and

set(figure,'defaultAxesColorOrder',[left_color; right_color]);

Try

hh=figure
set(hh,'defaultAxesColorOrder',[left_color; right_color]);
subplot(2,3,6)
left_color = [0 0 1];
right_color = [1 0 1];

yyaxis left
plot(rand(10,1),'b','LineWidth',2)
ylabel('pps')
hold on;
yyaxis right
plot(rand(10,1),'m--','LineWidth',3)
title('3-month T-bills');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis(2).Exponent = 0;

Unfortunately, it is still now working:

after I have ajusted the first 5 lines as:
hh=figure;
left_color = [0 0 1];
right_color = [1 0 1];
set(hh,‘defaultAxesColorOrder’,[left_color; right_color]);
subplot(2,3,6)

the results become:

anyway it’s not working…

As I said, I would need to see the full codes.

clear all; close all; clc;
load ert.csv;
load eprt_nocrisis.csv;

subplot(2,3,1)
plot(ert(:,12),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,12),'m--','LineWidth',3)
xlabel('quarters')
ylabel('pps')
title('3-month LIBOR (cy)');
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,2)
plot(ert(:,5),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,5),'m--','LineWidth',3)
title('Inflation (\pi)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 



subplot(2,3,3)
plot(ert(:,8),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,8),'m--','LineWidth',3)
title('Output (y)');
xlabel('quarters')
ylabel('%')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,4)
plot(ert(:,11),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,11),'m--','LineWidth',3)
title('Premium (pm)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,5)
plot(ert(:,16),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,16),'m--','LineWidth',3)
title('Unemployment (u)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


%hh=figure;
%left_color = [0 0 1];
%right_color = [1 0 1];
%set(hh,'defaultAxesColorOrder',[left_color; right_color]);

subplot(2,3,6)
yyaxis left
plot(ert(:,1),'b','LineWidth',2)
ylabel('pps')
hold on;
yyaxis right
plot(eprt_nocrisis(:,1),'m--','LineWidth',3)
title('3-month T-bills');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis(2).Exponent = 0;


Lgnd = legend('Monetary policy shock (\epsilon^r_t)','Macro-prudential shock (\epsilon^{pm}_t)');
set(Lgnd,'FontSize',12, 'FontName','Times','FontWeight','bold');
Lgnd.Position(1) = -0.01;
Lgnd.Position(2) = 0.42;

eprt_nocrisis.csv (9.2 KB) ert.csv (9.2 KB)

as you can see, I have commented out the problematic parts.

Hi, please could you have a look at my codes above?

I am still not sure I get what you are trying to do. How about

clear all; close all; clc;
load ert.csv;
load eprt_nocrisis.csv;

hh=figure;
subplot(2,3,1)
plot(ert(:,12),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,12),'m--','LineWidth',3)
xlabel('quarters')
ylabel('pps')
title('3-month LIBOR (cy)');
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,2)
plot(ert(:,5),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,5),'m--','LineWidth',3)
title('Inflation (\pi)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 



subplot(2,3,3)
plot(ert(:,8),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,8),'m--','LineWidth',3)
title('Output (y)');
xlabel('quarters')
ylabel('%')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,4)
plot(ert(:,11),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,11),'m--','LineWidth',3)
title('Premium (pm)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,5)
plot(ert(:,16),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,16),'m--','LineWidth',3)
title('Unemployment (u)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


left_color = [0 0 1];
right_color = [1 0 1];

hh2=subplot(2,3,6)
set(hh2,'defaultAxesColorOrder',[left_color; right_color]);
yyaxis left
plot(ert(:,1),'b','LineWidth',2)
ylabel('pps')
hold on;
yyaxis right
plot(eprt_nocrisis(:,1),'m--','LineWidth',3)
title('3-month T-bills');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis(2).Exponent = 0;


Lgnd = legend('Monetary policy shock (\epsilon^r_t)','Macro-prudential shock (\epsilon^{pm}_t)');
set(Lgnd,'FontSize',12, 'FontName','Times','FontWeight','bold');
Lgnd.Position(1) = -0.01;
Lgnd.Position(2) = 0.42;

Unfortunately, still not working…
all I am trying to do is changing the color of axis for one subplot only (subplot 6), leaving the rest ones in default.

When I run the full code above, I get

Hi, the problem is, the ajustment of the axis color for subplot 6 did not work…
if you commented out the
% left_color = [0 0 1];
%right_color = [1 0 1];
you will get exactly the same results.

Basically, the color of the axis in subplot 6 didn’t change the way I set .
in my orginal code, I set the right y axis of subplot 6 to be magenta (pink) [1 0 1], the same color with the pink dotted line.

but obviously it didn’t work, as the right axis turned red by default.

Try

clear all; close all; clc;
load ert.csv;
load eprt_nocrisis.csv;

hh=figure;
subplot(2,3,1)
plot(ert(:,12),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,12),'m--','LineWidth',3)
xlabel('quarters')
ylabel('pps')
title('3-month LIBOR (cy)');
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,2)
plot(ert(:,5),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,5),'m--','LineWidth',3)
title('Inflation (\pi)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 



subplot(2,3,3)
plot(ert(:,8),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,8),'m--','LineWidth',3)
title('Output (y)');
xlabel('quarters')
ylabel('%')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,4)
plot(ert(:,11),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,11),'m--','LineWidth',3)
title('Premium (pm)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


subplot(2,3,5)
plot(ert(:,16),'b','LineWidth',2)
hold on;
plot(eprt_nocrisis(:,16),'m--','LineWidth',3)
title('Unemployment (u)');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis.Exponent=0; 


left_color = [0 0 1];
right_color = [1 0 1];

subplot(2,3,6)
set(hh,'defaultAxesColorOrder',[left_color; right_color]);
yyaxis left
p1=plot(ert(:,1),'LineWidth',2);
ylabel('pps')
hold on;
yyaxis right
p2=plot(eprt_nocrisis(:,1),'--','LineWidth',3);

title('3-month T-bills');
xlabel('quarters')
ylabel('pps')
axis tight;
set(gca,'FontSize',16, 'FontName','Times')
ax = gca;
ax.YAxis(2).Exponent = 0;


Lgnd = legend('Monetary policy shock (\epsilon^r_t)','Macro-prudential shock (\epsilon^{pm}_t)');
set(Lgnd,'FontSize',12, 'FontName','Times','FontWeight','bold');
Lgnd.Position(1) = -0.01;
Lgnd.Position(2) = 0.42;
1 Like