2014-02-12 14:44:36 +01:00
|
|
|
function o = writeSeriesForGraph(o, fid, xrange)
|
|
|
|
%function o = writeSeriesForGraph(o, fid, xrange)
|
2014-01-22 00:24:24 +01:00
|
|
|
% Print a TikZ line
|
2013-03-27 16:20:59 +01:00
|
|
|
%
|
|
|
|
% INPUTS
|
2013-10-28 15:04:21 +01:00
|
|
|
% o [report_series] series object
|
|
|
|
% xrange [dates] range of x values for line
|
2013-03-27 16:20:59 +01:00
|
|
|
%
|
|
|
|
% OUTPUTS
|
2014-01-22 00:24:24 +01:00
|
|
|
% NONE
|
2013-03-27 16:20:59 +01:00
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
|
2014-01-22 00:24:24 +01:00
|
|
|
% Copyright (C) 2014 Dynare Team
|
2013-03-27 16:20:59 +01:00
|
|
|
%
|
|
|
|
% 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/>.
|
|
|
|
|
|
|
|
%% Validate options provided by user
|
2014-05-20 14:18:18 +02:00
|
|
|
if isempty(o.graphVline) && isempty(o.graphHline)
|
2014-05-20 11:33:57 +02:00
|
|
|
assert(~isempty(o.data) && isa(o.data, 'dseries'), ['@report_series.writeSeriesForGraph: must ' ...
|
|
|
|
'provide data as a dseries']);
|
|
|
|
end
|
2013-03-27 16:20:59 +01:00
|
|
|
|
2014-05-19 15:03:37 +02:00
|
|
|
assert(ischar(o.graphMiscTikzAddPlotOptions), ['@report_series.writeSeriesForGraph: ' ...
|
|
|
|
'graphMiscTikzAddPlotOptions file must be a string']);
|
|
|
|
|
2013-03-27 16:20:59 +01:00
|
|
|
% Line
|
2014-01-22 00:24:24 +01:00
|
|
|
valid_graphLineColor = {'red', 'green', 'blue', 'cyan ', 'magenta', 'yellow', ...
|
|
|
|
'black', 'gray', 'darkgray', 'lightgray', 'brown', ...
|
|
|
|
'lime', 'olive', 'orange', 'pink', 'purple', 'teal', 'violet', 'white'};
|
|
|
|
assert(any(strcmp(o.graphLineColor, valid_graphLineColor)), ...
|
2014-02-13 15:25:54 +01:00
|
|
|
['@report_series.writeSeriesForGraph: graphLineColor must be one of ' strjoin(valid_graphLineColor)]);
|
|
|
|
assert(ischar(o.graphLineStyle), '@report_series.writeSeriesForGraph: graphLineStyle must be a string');
|
2014-01-22 00:24:24 +01:00
|
|
|
assert(isfloat(o.graphLineWidth) && o.graphLineWidth > 0, ...
|
2014-02-13 15:25:54 +01:00
|
|
|
'@report_series.writeSeriesForGraph: graphLineWidth must be a positive number');
|
2013-03-27 16:20:59 +01:00
|
|
|
|
2013-05-13 17:06:48 +02:00
|
|
|
% GraphMarker
|
2014-02-12 16:13:35 +01:00
|
|
|
valid_graphMarker = {'x', '+', '-', '|', 'o', 'asterisk', 'star', '10-pointed star', 'oplus', ...
|
|
|
|
'oplus*', 'otimes', 'otimes*', 'square', 'square*', 'triangle', 'triangle*', 'diamond', ...
|
|
|
|
'diamond*', 'halfdiamond*', 'halfsquare*', 'halfsquare right*', ...
|
|
|
|
'halfsquare left*','Mercedes star','Mercedes star flipped','halfcircle',...
|
|
|
|
'halfcircle*','pentagon','pentagon star'};
|
2013-05-13 17:06:48 +02:00
|
|
|
assert(isempty(o.graphMarker) || any(strcmp(o.graphMarker, valid_graphMarker)), ...
|
2014-02-13 15:25:54 +01:00
|
|
|
['@report_series.writeSeriesForGraph: graphMarker must be one of ' strjoin(valid_graphMarker)]);
|
2013-03-27 16:20:59 +01:00
|
|
|
|
2014-02-13 15:25:54 +01:00
|
|
|
assert(ischar(o.graphMarkerEdgeColor), '@report_series.writeSeriesForGraph: graphMarkerEdgeColor must be a string');
|
|
|
|
assert(ischar(o.graphMarkerFaceColor), '@report_series.writeSeriesForGraph: graphMarkerFaceColor must be a string');
|
2014-02-03 15:52:36 +01:00
|
|
|
assert(isfloat(o.graphMarkerSize) && o.graphMarkerSize > 0, ...
|
2014-02-13 15:25:54 +01:00
|
|
|
'@report_series.writeSeriesForGraph: graphMarkerSize must be a positive number');
|
2013-03-27 16:20:59 +01:00
|
|
|
|
|
|
|
% Marker & Line
|
2014-02-13 15:25:54 +01:00
|
|
|
assert(~(strcmp(o.graphLineStyle, 'none') && isempty(o.graphMarker)), ['@report_series.writeSeriesForGraph: ' ...
|
2013-05-14 16:37:28 +02:00
|
|
|
'you must provide at least one of graphLineStyle and graphMarker']);
|
2013-03-27 16:20:59 +01:00
|
|
|
|
2014-05-20 11:33:57 +02:00
|
|
|
% Validate graphVline
|
|
|
|
assert(isdates(o.graphVline), '@report_series.writeSeriesForGraph: graphVline must be a dates');
|
2014-05-20 14:18:18 +02:00
|
|
|
assert(isempty(o.graphHline) || isnumeric(o.graphHline), ...
|
|
|
|
'@report_series.writeSeriesForGraph: graphHline must a single numeric value');
|
2013-03-27 16:20:59 +01:00
|
|
|
|
2013-07-24 16:40:01 +02:00
|
|
|
% Zero tolerance
|
2014-02-19 14:49:25 +01:00
|
|
|
assert(isfloat(o.zeroTol), '@report_series.write: zeroTol must be a float');
|
2013-07-24 16:40:01 +02:00
|
|
|
|
2014-05-20 11:33:57 +02:00
|
|
|
%% graphVline
|
|
|
|
|
2014-05-20 14:18:18 +02:00
|
|
|
if ~isempty(o.graphVline) || ~isempty(o.graphHline)
|
2014-05-20 11:33:57 +02:00
|
|
|
for i=1:o.graphVline.ndat
|
|
|
|
fprintf(fid, '%%vline %d\n\\begin{pgfonlayer}{background1}\n\\draw[color=%s,%s,line width=%fpt,line join=round',...
|
|
|
|
i, o.graphLineColor, o.graphLineStyle, o.graphLineWidth);
|
|
|
|
if ~isempty(o.graphMarker)
|
|
|
|
if isempty(o.graphMarkerEdgeColor)
|
|
|
|
o.graphMarkerEdgeColor = o.graphLineColor;
|
|
|
|
end
|
|
|
|
if isempty(o.graphMarkerFaceColor)
|
|
|
|
o.graphMarkerFaceColor = o.graphLineColor;
|
|
|
|
end
|
|
|
|
fprintf(fid, ',mark=%s,mark size=%f,every mark/.append style={draw=%s,fill=%s}',...
|
|
|
|
o.graphMarker,o.graphMarkerSize,o.graphMarkerEdgeColor,o.graphMarkerFaceColor);
|
|
|
|
end
|
|
|
|
if ~isempty(o.graphMiscTikzAddPlotOptions)
|
|
|
|
fprintf(fid, ',%s', o.graphMiscTikzAddPlotOptions);
|
|
|
|
end
|
|
|
|
stringsdd = strings(xrange);
|
|
|
|
x = find(strcmpi(date2string(o.graphVline(i)), stringsdd));
|
|
|
|
fprintf(fid, ['] (axis cs:%d,\\pgfkeysvalueof{/pgfplots/ymin}) -- (axis ' ...
|
|
|
|
'cs:%d,\\pgfkeysvalueof{/pgfplots/ymax});\n\\end{pgfonlayer}\n'], ...
|
|
|
|
x, x);
|
|
|
|
end
|
2014-05-20 14:18:18 +02:00
|
|
|
|
|
|
|
if ~isempty(o.graphHline)
|
|
|
|
fprintf(fid, '%%hline %d\n\\begin{pgfonlayer}{background1}\n\\draw[color=%s,%s,line width=%fpt,line join=round',...
|
|
|
|
i, o.graphLineColor, o.graphLineStyle, o.graphLineWidth);
|
|
|
|
if ~isempty(o.graphMarker)
|
|
|
|
if isempty(o.graphMarkerEdgeColor)
|
|
|
|
o.graphMarkerEdgeColor = o.graphLineColor;
|
|
|
|
end
|
|
|
|
if isempty(o.graphMarkerFaceColor)
|
|
|
|
o.graphMarkerFaceColor = o.graphLineColor;
|
|
|
|
end
|
|
|
|
fprintf(fid, ',mark=%s,mark size=%f,every mark/.append style={draw=%s,fill=%s}',...
|
|
|
|
o.graphMarker,o.graphMarkerSize,o.graphMarkerEdgeColor,o.graphMarkerFaceColor);
|
|
|
|
end
|
|
|
|
if ~isempty(o.graphMiscTikzAddPlotOptions)
|
|
|
|
fprintf(fid, ',%s', o.graphMiscTikzAddPlotOptions);
|
|
|
|
end
|
|
|
|
fprintf(fid, ['] (axis cs:\\pgfkeysvalueof{/pgfplots/xmin},%f) -- (axis ' ...
|
|
|
|
'cs:\\pgfkeysvalueof{/pgfplots/xmax},%f);\n\\end{pgfonlayer}\n'], ...
|
|
|
|
o.graphHline, o.graphHline);
|
|
|
|
end
|
2014-05-20 11:33:57 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-03-27 16:20:59 +01:00
|
|
|
%%
|
2013-12-13 15:35:43 +01:00
|
|
|
if isempty(xrange) || all(xrange == o.data.dates)
|
2013-03-29 16:28:35 +01:00
|
|
|
ds = o.data;
|
|
|
|
else
|
2013-03-27 16:20:59 +01:00
|
|
|
ds = o.data(xrange);
|
|
|
|
end
|
|
|
|
|
2014-02-19 14:49:25 +01:00
|
|
|
% if graphing data that is within zeroTol, set to zero, create report_series and
|
2013-07-24 16:40:01 +02:00
|
|
|
% get line:
|
|
|
|
thedata = ds.data;
|
|
|
|
stz = bsxfun(@and, ...
|
2014-02-19 14:49:25 +01:00
|
|
|
bsxfun(@lt, thedata, o.zeroTol), ...
|
|
|
|
bsxfun(@gt, thedata, -o.zeroTol));
|
2013-07-24 16:40:01 +02:00
|
|
|
if any(stz)
|
|
|
|
thedata(stz) = 0;
|
|
|
|
end
|
|
|
|
|
2014-02-11 18:26:28 +01:00
|
|
|
fprintf(fid, '%%series %s\n\\addplot[color=%s,%s,line width=%fpt,line join=round',...
|
2014-01-22 00:24:24 +01:00
|
|
|
o.data.name{:}, o.graphLineColor, o.graphLineStyle, o.graphLineWidth);
|
2014-02-12 16:13:35 +01:00
|
|
|
if ~isempty(o.graphMarker)
|
|
|
|
if isempty(o.graphMarkerEdgeColor)
|
|
|
|
o.graphMarkerEdgeColor = o.graphLineColor;
|
|
|
|
end
|
|
|
|
if isempty(o.graphMarkerFaceColor)
|
|
|
|
o.graphMarkerFaceColor = o.graphLineColor;
|
|
|
|
end
|
|
|
|
fprintf(fid, ',mark=%s,mark size=%f,every mark/.append style={draw=%s,fill=%s}',...
|
|
|
|
o.graphMarker,o.graphMarkerSize,o.graphMarkerEdgeColor,o.graphMarkerFaceColor);
|
|
|
|
end
|
2014-05-19 15:03:37 +02:00
|
|
|
if ~isempty(o.graphMiscTikzAddPlotOptions)
|
2014-05-19 16:31:37 +02:00
|
|
|
fprintf(fid, ',%s', o.graphMiscTikzAddPlotOptions);
|
2014-05-19 15:03:37 +02:00
|
|
|
end
|
2014-02-12 16:13:35 +01:00
|
|
|
fprintf(fid,']\ntable[row sep=crcr]{\nx y\\\\\n');
|
2014-01-22 00:24:24 +01:00
|
|
|
for i=1:ds.dates.ndat
|
|
|
|
fprintf(fid, '%d %f\\\\\n', i, thedata(i));
|
|
|
|
end
|
|
|
|
fprintf(fid,'};\n');
|
2013-03-27 16:20:59 +01:00
|
|
|
end
|