dynare/matlab/reports/@graph/createGraph.m

133 lines
3.3 KiB
Matlab
Raw Normal View History

2013-02-19 15:48:47 +01:00
function o = createGraph(o)
%function o = createGraph(o)
% Create the graph
%
% INPUTS
2013-03-13 18:02:29 +01:00
% o [graph] graph object
2013-02-19 15:48:47 +01:00
%
% OUTPUTS
2013-03-13 18:02:29 +01:00
% o [graph] graph object
2013-02-19 15:48:47 +01:00
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isempty(o.figname)
2013-03-08 19:25:24 +01:00
warning('@graph.createGraph: will overwrite %s with new graph\n', ...
o.figname);
2013-02-19 15:48:47 +01:00
end
if ~o.seriesElements.numElements()
warning('@graph.crepateGraph: no series to plot, returning');
return;
end
2013-03-07 15:45:53 +01:00
disp('creating plot..........');
2013-02-19 15:48:47 +01:00
h = figure('visible','off');
hold on;
box on;
2013-03-07 15:45:53 +01:00
if o.grid
grid on;
set(gca, 'GridLineStyle', '--');
end
2013-02-19 15:48:47 +01:00
if isempty(o.xrange)
dd = o.seriesElements.getMaxRange();
else
dd = o.xrange;
end
ne = o.seriesElements.numElements();
for i=1:ne
o.seriesElements(i).getLine(dd);
2013-02-19 15:48:47 +01:00
end
x = 1:1:dd.ndat;
xlabels = getDatesCellStringArray(dd);
2013-02-19 15:48:47 +01:00
2013-03-15 16:47:34 +01:00
if ~isempty(o.yrange)
ylim(o.yrange);
2013-03-13 15:38:24 +01:00
end
if o.zeroline
a = ylim;
if 0 > a(1) && 0 < a(2)
lh = line(xlim, [0 0], 'color', 'k', 'LineWidth', 0.25);
children =get(gca(), 'children');
children = [children(2:end); lh];
set(gca(), 'children', children);
end
end
2013-02-19 15:48:47 +01:00
if ~isempty(o.shade)
x1 = find(strcmpi(o.shade(1).format(), xlabels));
x2 = find(strcmpi(o.shade(o.shade.ndat).format(), xlabels));
2013-03-13 15:38:24 +01:00
assert(~isempty(x1) && ~isempty(x2), ['@graph.createGraph: either ' ...
o.shade(1).format() ' or ' o.shade(o.shade.ndat).format() ' is not in the date ' ...
2013-03-13 15:38:24 +01:00
'range of data selected.']);
2013-02-19 15:48:47 +01:00
yrange = get(gca, 'YLim');
% From ShadePlotForEmpahsis (Matlab Exchange)
% use patch bc area doesn't work with matlab2tikz
sh = patch([repmat(x1, 1, 2) repmat(x2, 1, 2)], ...
[yrange fliplr(yrange)], [0 1 0], ...
'FaceAlpha', .2);
children =get(gca(), 'children');
children = [children(2:end); sh];
set(gca(), 'children', children);
2013-02-19 15:48:47 +01:00
end
set(gca,'XTick', x);
set(gca,'XTickLabel', xlabels);
if o.legend
lh = legend(o.seriesElements.getNames());
2013-02-19 15:48:47 +01:00
set(lh, 'orientation', o.legend_orientation);
set(lh, 'Location', o.legend_location);
set(lh, 'FontSize', o.legend_font_size);
legend('boxoff');
end
if ~isempty(o.xlabel)
2013-03-08 18:59:26 +01:00
xlabel(['$\textbf{\footnotesize ' o.xlabel '}$'], 'Interpreter', 'LaTex');
2013-02-19 15:48:47 +01:00
end
if ~isempty(o.ylabel)
2013-03-08 18:59:26 +01:00
ylabel(['$\textbf{\footnotesize ' o.ylabel '}$'], 'Interpreter', 'LaTex');
2013-02-19 15:48:47 +01:00
end
if ~isempty(o.title)
2013-03-08 18:59:26 +01:00
title( o.title, 'Interpreter', 'LaTex');
2013-02-19 15:48:47 +01:00
end
drawnow;
o.figname = [tempname '.tex'];
2013-03-07 15:45:53 +01:00
disp(' converting to tex....');
2013-02-19 15:48:47 +01:00
matlab2tikz('filename', o.figname, ...
'showInfo', false, ...
'showWarnings', false, ...
'checkForUpdates', false);
2013-03-07 15:45:53 +01:00
grid off;
2013-02-19 15:48:47 +01:00
box off;
hold off;
close(h);
clear h;
end