createGraph.m 3.06 KB
Newer Older
Houtan Bastani's avatar
Houtan Bastani committed
1
2
3
4
5
function o = createGraph(o)
%function o = createGraph(o)
% Create the graph
%
% INPUTS
Houtan Bastani's avatar
Houtan Bastani committed
6
%   o   - Graph Object
Houtan Bastani's avatar
Houtan Bastani committed
7
8
%
% OUTPUTS
Houtan Bastani's avatar
Houtan Bastani committed
9
%   o   - Graph Object
Houtan Bastani's avatar
Houtan Bastani committed
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%
% 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/>.

assert(~isempty(o.data));
assert(isa(o.data, 'dynSeries')) ;

if ~isempty(o.figname)
35
36
    warning('@graph.createGraph: will overwrite %s with new graph\n', ...
            o.figname);
Houtan Bastani's avatar
Houtan Bastani committed
37
38
39
40
end

%o = readConfig(o);

Houtan Bastani's avatar
Houtan Bastani committed
41
disp('creating plot..........');
Houtan Bastani's avatar
Houtan Bastani committed
42
43
44
h = figure('visible','off');
hold on;
box on;
Houtan Bastani's avatar
Houtan Bastani committed
45
46
47
48
if o.grid
    grid on;
    set(gca, 'GridLineStyle', '--');
end
Houtan Bastani's avatar
Houtan Bastani committed
49
50
51
52
%set(0, 'CurrentFigure',h);
%set(h, 'PaperPositionMode', 'auto');
%set(h, 'units', 'normalized', 'outerposition', [0 0 1 1]);

Houtan Bastani's avatar
Houtan Bastani committed
53
if strcmpi(o.seriestouse, 'all')
Houtan Bastani's avatar
Houtan Bastani committed
54
55
    data = o.data.data;
else
Houtan Bastani's avatar
Houtan Bastani committed
56
    data = o.data{o.seriestouse{:}}.data;
Houtan Bastani's avatar
Houtan Bastani committed
57
58
59
60
61
62
63
64
65
66
67
68
end

x=[1:1:o.data.nobs];
xlabels=getDatesCellStringArray(o.data.time);

plot(x, data);

if ~isempty(o.shade)
    x1 = strmatch(lower(o.shade{1}), xlabels, 'exact');
    x2 = strmatch(lower(o.shade{2}), xlabels, 'exact');
    yrange = get(gca, 'YLim');

Houtan Bastani's avatar
Houtan Bastani committed
69
    if isempty(x1)
70
71
        error(['@graph.createGraph: ' o.shade{1} ' not in date range of ' ...
               'provided data']);
Houtan Bastani's avatar
Houtan Bastani committed
72
73
    end
    if isempty(x2)
74
75
        error(['@graph.createGraph: ' o.shade{2} ' not in date range of ' ...
               'provided data']);
Houtan Bastani's avatar
Houtan Bastani committed
76
77
    end

Houtan Bastani's avatar
Houtan Bastani committed
78
79
80
81
82
83
84
85
86
87
    % From ShadePlotForEmpahsis (Matlab Exchange)
    % use patch bc area doesn't work with matlab2tikz
    patch([repmat(x1, 1, 2) repmat(x2, 1, 2)], [yrange fliplr(yrange)], ...
          'b', 'FaceAlpha', .2);
end

set(gca,'XTick', x);
set(gca,'XTickLabel', xlabels);

if o.legend
Houtan Bastani's avatar
Houtan Bastani committed
88
    if strcmpi(o.seriestouse, 'all')
Houtan Bastani's avatar
Houtan Bastani committed
89
90
        lh = legend(o.data.name);
    else
Houtan Bastani's avatar
Houtan Bastani committed
91
        lh = legend(o.seriestouse{:});
Houtan Bastani's avatar
Houtan Bastani committed
92
93
94
95
96
97
98
99
    end
    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)
Houtan Bastani's avatar
Houtan Bastani committed
100
    xlabel(['$\textbf{\footnotesize ' o.xlabel '}$'], 'Interpreter', 'LaTex');
Houtan Bastani's avatar
Houtan Bastani committed
101
102
103
end

if ~isempty(o.ylabel)
Houtan Bastani's avatar
Houtan Bastani committed
104
    ylabel(['$\textbf{\footnotesize ' o.ylabel '}$'], 'Interpreter', 'LaTex');
Houtan Bastani's avatar
Houtan Bastani committed
105
106
107
end

if ~isempty(o.title)
Houtan Bastani's avatar
Houtan Bastani committed
108
    title( o.title, 'Interpreter', 'LaTex');
Houtan Bastani's avatar
Houtan Bastani committed
109
110
111
112
end
drawnow;

o.figname = ['figure-' num2str(cputime) '.tex'];
Houtan Bastani's avatar
Houtan Bastani committed
113
disp('  converting to tex....');
Houtan Bastani's avatar
Houtan Bastani committed
114
115
116
117
118
matlab2tikz('filename', o.figname, ...
            'showInfo', false, ...
            'showWarnings', false, ...
            'checkForUpdates', false);

Houtan Bastani's avatar
Houtan Bastani committed
119
grid off;
Houtan Bastani's avatar
Houtan Bastani committed
120
121
122
123
124
box off;
hold off;
close(h);
clear h;
end