- 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
label = mydata.shock_group.label;
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)];
for j=1:length(shocks)
M.shock_groups.(options.use_shock_groups).(['group' int2str(j)]).label=shocks{j};
@ -43,6 +43,7 @@ for j=1:length(shocks)
end
options.shock_decomp.interactive=0;
options.shock_decomp.expand=1;
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
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
GraphDirectoryName = CheckPath('graphs',DynareModel.dname);
new_colormap = DynareOptions.colormap;
% 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')
SteadyState = opts_decomp.steady_state;
end
if ~isempty(opts_decomp.fig_mode)
fig_mode = opts_decomp.fig_mode;
if ~isempty(opts_decomp.type)
fig_mode = opts_decomp.type;
fig_mode1 = ['_' fig_mode];
fig_mode = [fig_mode '_'];
end
fig_names = opts_decomp.fig_names;
fig_names_long = opts_decomp.fig_names;
use_shock_groups = DynareOptions.use_shock_groups;
screen_shocks = opts_decomp.screen_shocks;
if use_shock_groups | comp_nbr<=18,
@ -58,8 +60,13 @@ if use_shock_groups
shock_ind = fieldnames(shock_groups);
end
if screen_shocks
fig_names = [fig_names '_screen'];
fig_names_long = [fig_names_long ' SCREEN'];
end
fig_names=regexprep(fig_names_long, ' ', '_');
fig_names=strrep(fig_names, '.', '');
fig_names=strrep(fig_names, '-', '');
interactive = opts_decomp.interactive;
@ -76,7 +83,7 @@ nvar = length(i_var);
%% write LaTeX-Header
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,['%% ' datestr(now,0) '\n']);
fprintf(fidTeX,' \n');
@ -110,7 +117,7 @@ for j=1:nvar
if ymax-ymin < 1e-6
continue
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])
ax=axes('Position',[0.1 0.1 0.6 0.8],'box','on');
% plot(ax,x(2:end),z1(end,:),'k-','LineWidth',2)
@ -192,13 +199,13 @@ for j=1:nvar
colormap(new_colormap)
end
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)))
fprintf(fidTeX,'\\begin{figure}[H]\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,'\\label{Fig:shock_decomp:%s}\n',deblank(endo_names(i_var(j),:)));
fprintf(fidTeX,'\\caption{Historical shock decomposition: $ %s $}\n',deblank(DynareModel.endo_names_tex(i_var(j),:)));
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',[fig_mode deblank(endo_names(i_var(j),:)) fig_names]);
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,' \n');
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
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
GraphDirectoryName = CheckPath('graphs',DynareModel.dname);
% interactive = 0;
fig_mode='';
fig_mode1='';
@ -45,8 +46,8 @@ comp_nbr = size(z,2)-1;
opts_decomp = DynareOptions.shock_decomp;
interactive = opts_decomp.interactive;
if ~isempty(opts_decomp.fig_mode)
fig_mode = opts_decomp.fig_mode;
if ~isempty(opts_decomp.type)
fig_mode = opts_decomp.type;
fig_mode1 = ['_' fig_mode];
fig_mode = [fig_mode '_'];
end
@ -54,15 +55,18 @@ screen_shocks = opts_decomp.screen_shocks;
if DynareOptions.use_shock_groups | comp_nbr<=18,
screen_shocks=0;
end
fig_names = opts_decomp.fig_names;
fig_names_long = opts_decomp.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);
if isempty(initial_date)
@ -97,7 +101,7 @@ nvar = length(i_var);
%% write LaTeX-Header
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,['%% ' datestr(now,0) '\n']);
fprintf(fidTeX,' \n');
@ -136,7 +140,7 @@ for j=1:nvar
continue
end
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(3)=inf;
a0(4)=-inf;
@ -184,17 +188,17 @@ for j=1:nvar
set(gca,'ylim',a0(3:4))
end
if nfigs>1,
suffix = ['detail_' int2str(jf)];
suffix = ['_detail_' int2str(jf)];
else
suffix = ['detail'];
suffix = ['_detail'];
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)))
fprintf(fidTeX,'\\begin{figure}[H]\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,'\\label{Fig:shock_decomp:%s}\n',deblank(endo_names(i_var(j),:)));
fprintf(fidTeX,'\\caption{Historical shock decomposition: $ %s $}\n',deblank(DynareModel.endo_names_tex(i_var(j),:)));
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_detail:%s}\n',[fig_mode deblank(endo_names(i_var(j),:)) fig_names suffix]);
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,' \n');
end

View File

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