- removed useless internal option fig_mode

- better captions/figure nsmes
- moved plots to graphs subdir
- fixed latex issuea [label and caption].
time-shift
Marco Ratto 2017-01-19 16:55:10 +01:00 committed by Stéphane Adjemian (Charybdis)
parent 10773e2cbb
commit 3fdf7be6e8
4 changed files with 58 additions and 40 deletions

View File

@ -35,7 +35,7 @@ mydata=get(findobj(gcf,'tag',['group' int2str(ic)]),'userdata');
% define expanded group % define expanded group
label = mydata.shock_group.label; label = mydata.shock_group.label;
shocks = mydata.shock_group.shocks; shocks = mydata.shock_group.shocks;
options.shock_decomp.fig_names = [mydata.fig_names '_expand']; options.shock_decomp.fig_names = [mydata.fig_names '. Expand'];
options.use_shock_groups = strrep(label,' ','_'); %[use_shock_groups_old int2str(ic)]; options.use_shock_groups = strrep(label,' ','_'); %[use_shock_groups_old int2str(ic)];
for j=1:length(shocks) for j=1:length(shocks)
M.shock_groups.(options.use_shock_groups).(['group' int2str(j)]).label=shocks{j}; M.shock_groups.(options.use_shock_groups).(['group' int2str(j)]).label=shocks{j};
@ -43,6 +43,7 @@ for j=1:length(shocks)
end end
options.shock_decomp.interactive=0; options.shock_decomp.interactive=0;
options.shock_decomp.expand=1;
plot_shock_decomposition(M,oo,options,var_list_); plot_shock_decomposition(M,oo,options,var_list_);

View File

@ -28,6 +28,7 @@ function []=graph_decomp(z,shock_names,endo_names,i_var,initial_date,DynareModel
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
GraphDirectoryName = CheckPath('graphs',DynareModel.dname);
new_colormap = DynareOptions.colormap; new_colormap = DynareOptions.colormap;
% number of components equals number of shocks + 1 (initial conditions) % number of components equals number of shocks + 1 (initial conditions)
@ -42,12 +43,13 @@ opts_decomp = DynareOptions.shock_decomp;
if isfield(opts_decomp,'steady_state') if isfield(opts_decomp,'steady_state')
SteadyState = opts_decomp.steady_state; SteadyState = opts_decomp.steady_state;
end end
if ~isempty(opts_decomp.fig_mode) if ~isempty(opts_decomp.type)
fig_mode = opts_decomp.fig_mode; fig_mode = opts_decomp.type;
fig_mode1 = ['_' fig_mode]; fig_mode1 = ['_' fig_mode];
fig_mode = [fig_mode '_']; fig_mode = [fig_mode '_'];
end end
fig_names = opts_decomp.fig_names; fig_names_long = opts_decomp.fig_names;
use_shock_groups = DynareOptions.use_shock_groups; use_shock_groups = DynareOptions.use_shock_groups;
screen_shocks = opts_decomp.screen_shocks; screen_shocks = opts_decomp.screen_shocks;
if use_shock_groups | comp_nbr<=18, if use_shock_groups | comp_nbr<=18,
@ -58,8 +60,13 @@ if use_shock_groups
shock_ind = fieldnames(shock_groups); shock_ind = fieldnames(shock_groups);
end end
if screen_shocks if screen_shocks
fig_names = [fig_names '_screen']; fig_names_long = [fig_names_long ' SCREEN'];
end end
fig_names=regexprep(fig_names_long, ' ', '_');
fig_names=strrep(fig_names, '.', '');
fig_names=strrep(fig_names, '-', '');
interactive = opts_decomp.interactive; interactive = opts_decomp.interactive;
@ -76,7 +83,7 @@ nvar = length(i_var);
%% write LaTeX-Header %% write LaTeX-Header
if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format))) if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format)))
fidTeX = fopen([DynareModel.fname '_shock_decomp' fig_mode1 fig_names '.tex'],'w'); fidTeX = fopen([GraphDirectoryName, filesep, DynareModel.fname '_shock_decomp' fig_mode1 fig_names '.tex'],'w');
fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp.m.\n'); fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp.m.\n');
fprintf(fidTeX,['%% ' datestr(now,0) '\n']); fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n');
@ -110,7 +117,7 @@ for j=1:nvar
if ymax-ymin < 1e-6 if ymax-ymin < 1e-6
continue continue
end end
fhandle = dyn_figure(DynareOptions,'Name',['Shock decomposition: ' deblank(endo_names(i_var(j),:)) fig_mode1 fig_names], 'PaperPositionMode', 'auto','PaperOrientation','landscape','renderermode','auto'); fhandle = dyn_figure(DynareOptions,'Name',['Shock decomposition: ' deblank(endo_names(i_var(j),:)) strrep(fig_mode1, '_', ' ') fig_names_long '.'], 'PaperPositionMode', 'auto','PaperOrientation','landscape','renderermode','auto');
set(fhandle,'position' ,[50 50 1500 750]) set(fhandle,'position' ,[50 50 1500 750])
ax=axes('Position',[0.1 0.1 0.6 0.8],'box','on'); ax=axes('Position',[0.1 0.1 0.6 0.8],'box','on');
% plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2) % plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2)
@ -192,13 +199,13 @@ for j=1:nvar
colormap(new_colormap) colormap(new_colormap)
end end
hold off hold off
dyn_saveas(fhandle,[DynareModel.fname,'_shock_decomposition_',fig_mode,deblank(endo_names(i_var(j),:)),fig_names],DynareOptions); dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',fig_mode,deblank(endo_names(i_var(j),:)),fig_names],DynareOptions);
if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format))) if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format)))
fprintf(fidTeX,'\\begin{figure}[H]\n'); fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n'); fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,['\\includegraphics[width=0.8\\textwidth]{%s_shock_decomposition_%s}\n'],DynareModel.fname,[fig_mode deblank(endo_names(i_var(j),:)) fig_names]); fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[fig_mode deblank(endo_names(i_var(j),:)) fig_names]);
fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',deblank(endo_names(i_var(j),:))); fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_names]);
fprintf(fidTeX,'\\caption{Historical shock decomposition: $ %s $}\n',deblank(DynareModel.endo_names_tex(i_var(j),:))); fprintf(fidTeX,['\\caption{Historical shock decomposition: $ %s $ ' strrep(fig_mode1, '_', ' ') fig_names_long '.}\n'],deblank(DynareModel.endo_names_tex(i_var(j),:)));
fprintf(fidTeX,'\\end{figure}\n'); fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n');
end end

View File

@ -28,6 +28,7 @@ function []=graph_decomp_detail(z,shock_names,endo_names,i_var,initial_date,Dyna
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
GraphDirectoryName = CheckPath('graphs',DynareModel.dname);
% interactive = 0; % interactive = 0;
fig_mode=''; fig_mode='';
fig_mode1=''; fig_mode1='';
@ -45,8 +46,8 @@ comp_nbr = size(z,2)-1;
opts_decomp = DynareOptions.shock_decomp; opts_decomp = DynareOptions.shock_decomp;
interactive = opts_decomp.interactive; interactive = opts_decomp.interactive;
if ~isempty(opts_decomp.fig_mode) if ~isempty(opts_decomp.type)
fig_mode = opts_decomp.fig_mode; fig_mode = opts_decomp.type;
fig_mode1 = ['_' fig_mode]; fig_mode1 = ['_' fig_mode];
fig_mode = [fig_mode '_']; fig_mode = [fig_mode '_'];
end end
@ -54,15 +55,18 @@ screen_shocks = opts_decomp.screen_shocks;
if DynareOptions.use_shock_groups | comp_nbr<=18, if DynareOptions.use_shock_groups | comp_nbr<=18,
screen_shocks=0; screen_shocks=0;
end end
fig_names = opts_decomp.fig_names; fig_names_long = opts_decomp.fig_names;
% fig_names = ['_' fig_names]; % fig_names = ['_' fig_names];
fig_names1 = [fig_names];
fig_names = [fig_names '_'];
if screen_shocks
fig_names1 = [fig_names1 '_screen'];
fig_names = [fig_names 'screen_'];
end
if screen_shocks
% fig_names1 = [fig_names1 '_screen'];
fig_names = [fig_names ' SCREEN'];
end
fig_names=regexprep(fig_names_long, ' ', '_');
fig_names=strrep(fig_names, '.', '');
fig_names=strrep(fig_names, '-', '');
% fig_names1 = [fig_names];
% fig_names = [fig_names '_'];
gend = size(z,3); gend = size(z,3);
if isempty(initial_date) if isempty(initial_date)
@ -97,7 +101,7 @@ nvar = length(i_var);
%% write LaTeX-Header %% write LaTeX-Header
if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format))) if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format)))
fidTeX = fopen([DynareModel.fname '_shock_decomp' fig_mode1 fig_names1 '_detail.tex'],'w'); fidTeX = fopen([GraphDirectoryName, filesep, DynareModel.fname '_shock_decomp' fig_mode1 fig_names '_detail.tex'],'w');
fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp_detail.m.\n'); fprintf(fidTeX,'%% TeX eps-loader file generated by Dynare''s graph_decomp_detail.m.\n');
fprintf(fidTeX,['%% ' datestr(now,0) '\n']); fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n');
@ -136,7 +140,7 @@ for j=1:nvar
continue continue
end end
for jf = 1:nfigs for jf = 1:nfigs
fhandle = dyn_figure(DynareOptions,'Name',['Shock decomposition (detail): ' deblank(endo_names(i_var(j),:)) fig_mode1 fig_names1],'position',[200 100 650 850], 'PaperPositionMode', 'auto','PaperOrientation','portrait','renderermode','auto'); fhandle = dyn_figure(DynareOptions,'Name',['Shock decomposition (detail): ' deblank(endo_names(i_var(j),:)) strrep(fig_mode1, '_', ' ') fig_names_long '.'],'position',[200 100 650 850], 'PaperPositionMode', 'auto','PaperOrientation','portrait','renderermode','auto');
a0=zeros(1,4); a0=zeros(1,4);
a0(3)=inf; a0(3)=inf;
a0(4)=-inf; a0(4)=-inf;
@ -184,17 +188,17 @@ for j=1:nvar
set(gca,'ylim',a0(3:4)) set(gca,'ylim',a0(3:4))
end end
if nfigs>1, if nfigs>1,
suffix = ['detail_' int2str(jf)]; suffix = ['_detail_' int2str(jf)];
else else
suffix = ['detail']; suffix = ['_detail'];
end end
dyn_saveas(fhandle,[DynareModel.fname,'_shock_decomposition_',fig_mode,deblank(endo_names(i_var(j),:)),fig_names suffix],DynareOptions); dyn_saveas(fhandle,[GraphDirectoryName, filesep, DynareModel.fname,'_shock_decomposition_',fig_mode,deblank(endo_names(i_var(j),:)),fig_names suffix],DynareOptions);
if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format))) if DynareOptions.TeX && any(strcmp('eps',cellstr(DynareOptions.graph_format)))
fprintf(fidTeX,'\\begin{figure}[H]\n'); fprintf(fidTeX,'\\begin{figure}[H]\n');
fprintf(fidTeX,'\\centering \n'); fprintf(fidTeX,'\\centering \n');
fprintf(fidTeX,['\\includegraphics[width=0.8\\textwidth]{%s_shock_decomposition_%s}\n'],DynareModel.fname,[fig_mode deblank(endo_names(i_var(j),:)) fig_names suffix]); fprintf(fidTeX,'\\includegraphics[width=0.8\\textwidth]{%s/graphs/%s_shock_decomposition_%s}\n',DynareModel.fname,DynareModel.fname,[fig_mode deblank(endo_names(i_var(j),:)) fig_names suffix]);
fprintf(fidTeX,'\\label{Fig:shock_decomp:%s}\n',deblank(endo_names(i_var(j),:))); fprintf(fidTeX,'\\label{Fig:shock_decomp_detail:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_names suffix]);
fprintf(fidTeX,'\\caption{Historical shock decomposition: $ %s $}\n',deblank(DynareModel.endo_names_tex(i_var(j),:))); fprintf(fidTeX,['\\caption{Historical shock decomposition: $ %s $ ' strrep(fig_mode1, '_', ' ') fig_names_long, '.}\n'],deblank(DynareModel.endo_names_tex(i_var(j),:)));
fprintf(fidTeX,'\\end{figure}\n'); fprintf(fidTeX,'\\end{figure}\n');
fprintf(fidTeX,' \n'); fprintf(fidTeX,' \n');
end end

View File

@ -49,8 +49,14 @@ fig_names='';
% steadystate=0; % steadystate=0;
% write_xls=0; % write_xls=0;
if isfield(options_.shock_decomp,'expand'), % private trap for uimenu calls
expand=options_.shock_decomp.expand;
else
expand=0;
end
if ~isempty(options_.shock_decomp.fig_names) if ~isempty(options_.shock_decomp.fig_names)
fig_names=['_' options_.shock_decomp.fig_names]; fig_names=[' ' options_.shock_decomp.fig_names];
end end
type=options_.shock_decomp.type; type=options_.shock_decomp.type;
detail_plot=options_.shock_decomp.detail_plot; detail_plot=options_.shock_decomp.detail_plot;
@ -66,43 +72,47 @@ switch realtime_
case 0 case 0
z = oo_.shock_decomposition; z = oo_.shock_decomposition;
fig_names1=fig_names;
case 1 % realtime case 1 % realtime
if vintage_ if vintage_
z = oo_.realtime_shock_decomposition.(['time_' int2str(vintage_)]); z = oo_.realtime_shock_decomposition.(['time_' int2str(vintage_)]);
fig_names=[fig_names '_realtime_' char(initial_date+vintage_-1)]; fig_names1=[fig_names ' realtime. ' char(initial_date+vintage_-1)];
else else
z = oo_.realtime_shock_decomposition.pool; z = oo_.realtime_shock_decomposition.pool;
fig_names=[fig_names '_realtime_pool']; fig_names1=[fig_names ' realtime pool'];
end end
case 2 % conditional case 2 % conditional
if vintage_ if vintage_
z = oo_.conditional_shock_decomposition.(['time_' int2str(vintage_)]); z = oo_.conditional_shock_decomposition.(['time_' int2str(vintage_)]);
initial_date = options_.initial_date+vintage_-forecast_; initial_date = options_.initial_date+vintage_-forecast_;
fig_names=[fig_names '_conditional_' int2str(forecast_) 'step_' char(initial_date)]; fig_names1=[fig_names ' conditional ' int2str(forecast_) '-step ' char(initial_date)];
else else
z = oo_.conditional_shock_decomposition.pool; z = oo_.conditional_shock_decomposition.pool;
fig_names=[fig_names '_conditional_pool']; fig_names1=[fig_names ' conditional pool'];
end end
case 3 % forecast case 3 % forecast
if vintage_ if vintage_
z = oo_.realtime_forecast_shock_decomposition.(['time_' int2str(vintage_)]); z = oo_.realtime_forecast_shock_decomposition.(['time_' int2str(vintage_)]);
initial_date = options_.initial_date+vintage_-1; initial_date = options_.initial_date+vintage_-1;
fig_names=[fig_names '_forecast_' int2str(forecast_) 'step_' char(initial_date)]; fig_names1=[fig_names ' forecast ' int2str(forecast_) '-step ' char(initial_date)];
else else
z = oo_.realtime_forecast_shock_decomposition.pool; z = oo_.realtime_forecast_shock_decomposition.pool;
fig_names=[fig_names '_forecast_1step_pool']; fig_names1=[fig_names ' forecast 1-step pool'];
end end
end end
if ~expand
fig_names = fig_names1;
end
gend = size(z,3); gend = size(z,3);
if options_.use_shock_groups if options_.use_shock_groups
shock_groups = M_.shock_groups.(options_.use_shock_groups); shock_groups = M_.shock_groups.(options_.use_shock_groups);
shock_ind = fieldnames(shock_groups); shock_ind = fieldnames(shock_groups);
ngroups = length(shock_ind); ngroups = length(shock_ind);
fig_names=[fig_names '_group_' options_.use_shock_groups]; fig_names=[fig_names ' group ' options_.use_shock_groups];
shock_names = shock_ind; shock_names = shock_ind;
for i=1:ngroups, for i=1:ngroups,
shock_names{i} = (shock_groups.(shock_ind{i}).label); shock_names{i} = (shock_groups.(shock_ind{i}).label);
@ -141,7 +151,6 @@ if isempty(options_.colormap),
options_.colormap = MAP; options_.colormap = MAP;
end end
steady_state = oo_.steady_state; steady_state = oo_.steady_state;
fig_mode=type;
switch type switch type
@ -156,7 +165,6 @@ switch type
else else
initial_date = dates('0Q4'); initial_date = dates('0Q4');
end end
fig_mode = type;
steady_state = 4*steady_state; steady_state = 4*steady_state;
case 'aoa' case 'aoa'
@ -169,7 +177,6 @@ switch type
t0=4-initial_date.time(2)+1; t0=4-initial_date.time(2)+1;
end end
z=z(:,:,t0:4:end); z=z(:,:,t0:4:end);
fig_mode = 'AoA';
otherwise otherwise
@ -179,7 +186,6 @@ end
if steadystate if steadystate
options_.shock_decomp.steady_state=steady_state; options_.shock_decomp.steady_state=steady_state;
end end
options_.shock_decomp.fig_mode=fig_mode;
options_.shock_decomp.fig_names=fig_names; options_.shock_decomp.fig_names=fig_names;
if detail_plot, if detail_plot,
graph_decomp_detail(z,shock_names,M_.endo_names,i_var,initial_date,M_,options_) graph_decomp_detail(z,shock_names,M_.endo_names,i_var,initial_date,M_,options_)