2019-08-27 17:38:20 +02:00
|
|
|
function writeSeriesForGraph(o, fid, xrange, series_num)
|
|
|
|
%function writeSeriesForGraph(o, fid, xrange, series_num)
|
2014-01-22 00:24:24 +01:00
|
|
|
% Print a TikZ line
|
2013-03-27 16:20:59 +01:00
|
|
|
%
|
|
|
|
% INPUTS
|
2019-08-27 17:38:20 +02:00
|
|
|
% o [report_series] series object
|
|
|
|
% xrange [dates] range of x values for line
|
|
|
|
% series_num [int] the number of this series in the total number of series passed to this graph
|
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
|
|
|
|
|
2022-04-13 13:14:04 +02:00
|
|
|
% Copyright © 2014-2019 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
|
2021-06-09 17:15:17 +02:00
|
|
|
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2013-03-27 16:20:59 +01:00
|
|
|
|
|
|
|
%% Validate options provided by user
|
2014-05-20 14:18:18 +02:00
|
|
|
if isempty(o.graphVline) && isempty(o.graphHline)
|
2014-05-20 14:50:28 +02:00
|
|
|
assert(~isempty(o.data) && isdseries(o.data), ['@report_series.writeSeriesForGraph: must ' ...
|
2014-05-20 11:33:57 +02:00
|
|
|
'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']);
|
2014-12-23 15:32:54 +01:00
|
|
|
assert(islogical(o.graphShowInLegend), ['@report_series.writeSeriesForGraph: ' ...
|
|
|
|
'graphShowInLegend must be either true or false']);
|
2014-05-19 15:03:37 +02:00
|
|
|
|
2013-03-27 16:20:59 +01:00
|
|
|
% Line
|
2014-06-27 17:06:45 +02:00
|
|
|
assert(ischar(o.graphLineColor), '@report_series.writeSeriesForGraph: graphLineColor must be a string');
|
2014-02-13 15:25:54 +01:00
|
|
|
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, ...
|
2017-05-19 00:04:08 +02:00
|
|
|
'@report_series.writeSeriesForGraph: graphLineWidth must be a positive number');
|
2013-03-27 16:20:59 +01:00
|
|
|
|
2014-12-23 16:27:22 +01:00
|
|
|
% Bar
|
|
|
|
assert(islogical(o.graphBar), '@report_series.writeSeriesForGraph: graphBar must be either true or false');
|
|
|
|
assert(ischar(o.graphBarColor), '@report_series.writeSeriesForGraph: graphBarColor must be a string');
|
|
|
|
assert(ischar(o.graphBarFillColor), '@report_series.writeSeriesForGraph: graphBarFillColor must be a string');
|
|
|
|
assert(isfloat(o.graphBarWidth) && o.graphBarWidth > 0, ...
|
2017-05-19 00:04:08 +02:00
|
|
|
'@report_series.writeSeriesForGraph: graphbarWidth must be a positive number');
|
2014-12-23 16:27:22 +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)), ...
|
2016-02-24 14:38:20 +01:00
|
|
|
['@report_series.writeSeriesForGraph: graphMarker must be one of ' addCommasToCellStr(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, ...
|
2017-05-19 00:04:08 +02: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
|
2014-05-20 14:28:59 +02:00
|
|
|
assert(isempty(o.graphVline) || (isdates(o.graphVline) && o.graphVline.ndat == 1), ...
|
2017-05-19 00:04:08 +02:00
|
|
|
'@report_series.writeSeriesForGraph: graphVline must be a dates of size one');
|
2014-05-20 14:18:18 +02:00
|
|
|
assert(isempty(o.graphHline) || isnumeric(o.graphHline), ...
|
2017-05-19 00:04:08 +02:00
|
|
|
'@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
|
|
|
|
2015-04-27 18:16:05 +02:00
|
|
|
% Fan Chart
|
|
|
|
assert(ischar(o.graphFanShadeColor), '@report_series.writeSeriesForGraph: graphFanShadeColor must be a string');
|
|
|
|
assert(isint(o.graphFanShadeOpacity), '@report_series.writeSeriesForGraph: graphFanShadeOpacity must be an int');
|
|
|
|
|
2014-05-20 14:34:15 +02:00
|
|
|
%% graphVline && graphHline
|
|
|
|
if ~isempty(o.graphVline)
|
2015-04-24 16:13:16 +02:00
|
|
|
fprintf(fid, '%%Vertical Line\n\\begin{pgfonlayer}{axis lines}\n\\draw');
|
2015-04-27 18:16:05 +02:00
|
|
|
writeLineOptions(o, fid, series_num);
|
2014-05-20 14:34:15 +02:00
|
|
|
stringsdd = strings(xrange);
|
|
|
|
x = find(strcmpi(date2string(o.graphVline), stringsdd));
|
|
|
|
fprintf(fid, ['(axis cs:%d,\\pgfkeysvalueof{/pgfplots/ymin}) -- (axis ' ...
|
2017-05-19 00:04:08 +02:00
|
|
|
'cs:%d,\\pgfkeysvalueof{/pgfplots/ymax});\n\\end{pgfonlayer}\n'], ...
|
|
|
|
x, x);
|
2014-05-20 14:34:15 +02:00
|
|
|
end
|
|
|
|
if ~isempty(o.graphHline)
|
2015-04-24 16:13:16 +02:00
|
|
|
fprintf(fid, '%%Horizontal Line\n\\begin{pgfonlayer}{axis lines}\n\\addplot');
|
2015-04-27 18:16:05 +02:00
|
|
|
writeLineOptions(o, fid, series_num);
|
2014-05-22 17:03:52 +02:00
|
|
|
fprintf(fid, ['coordinates {(\\pgfkeysvalueof{/pgfplots/xmin},%f)' ...
|
|
|
|
'(\\pgfkeysvalueof{/pgfplots/xmax},%f)};\n\\end{pgfonlayer}\n'], ...
|
|
|
|
o.graphHline, o.graphHline);
|
2014-05-20 14:34:15 +02:00
|
|
|
end
|
2014-05-20 14:18:18 +02:00
|
|
|
if ~isempty(o.graphVline) || ~isempty(o.graphHline)
|
2014-05-20 14:34:15 +02:00
|
|
|
% return since the code below assumes that o.data exists
|
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-05-22 19:01:48 +02:00
|
|
|
thedata = setDataToZeroFromZeroTol(o, ds);
|
2014-05-20 14:34:15 +02:00
|
|
|
fprintf(fid, '%%series %s\n\\addplot', o.data.name{:});
|
2015-04-27 18:16:05 +02:00
|
|
|
writeLineOptions(o, fid, series_num);
|
2014-05-20 14:34:15 +02:00
|
|
|
fprintf(fid,'\ntable[row sep=crcr]{\nx y\\\\\n');
|
|
|
|
for i=1:ds.dates.ndat
|
2015-10-15 12:32:24 +02:00
|
|
|
if ~isnan(thedata(i))
|
|
|
|
fprintf(fid, '%d %f\\\\\n', i, thedata(i));
|
2015-10-15 11:16:13 +02:00
|
|
|
end
|
2014-05-20 14:34:15 +02:00
|
|
|
end
|
|
|
|
fprintf(fid,'};\n');
|
2015-04-27 18:16:05 +02:00
|
|
|
|
|
|
|
% For Fan charts
|
2015-04-28 16:35:58 +02:00
|
|
|
if ispc || ismac
|
2017-05-19 00:04:08 +02:00
|
|
|
if ~isempty(o.graphFanShadeColor)
|
|
|
|
assert(isint(series_num) && series_num > 1, ['@report_series.writeSeriesForGraph: can only add '...
|
|
|
|
'graphFanShadeColor and graphFanShadeOpacity starting from the ' ...
|
|
|
|
'second series in the graph']);
|
|
|
|
fprintf(fid, '\\addplot[%s!%d, forget plot] fill between[of=%d and %d];\n', ...
|
|
|
|
o.graphFanShadeColor, o.graphFanShadeOpacity, series_num, series_num - 1);
|
|
|
|
end
|
2015-04-27 18:16:05 +02:00
|
|
|
end
|
2014-05-20 14:34:15 +02:00
|
|
|
end
|
|
|
|
|
2015-04-27 18:16:05 +02:00
|
|
|
function writeLineOptions(o, fid, series_num)
|
2014-12-23 16:27:22 +01:00
|
|
|
if o.graphBar
|
2014-12-29 20:22:14 +01:00
|
|
|
fprintf(fid, '[ybar,ybar legend,color=%s,fill=%s,line width=%fpt',...
|
2014-12-23 16:27:22 +01:00
|
|
|
o.graphBarColor, o.graphBarFillColor, o.graphBarWidth);
|
|
|
|
else
|
|
|
|
fprintf(fid, '[color=%s,%s,line width=%fpt,line join=round',...
|
|
|
|
o.graphLineColor, o.graphLineStyle, o.graphLineWidth);
|
2014-05-20 14:34:15 +02:00
|
|
|
|
2014-12-23 16:27:22 +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);
|
2014-02-12 16:13:35 +01:00
|
|
|
end
|
|
|
|
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
|
2015-04-28 16:35:58 +02:00
|
|
|
if isunix && ~ismac
|
2017-05-19 00:04:08 +02:00
|
|
|
fprintf(fid,']');
|
2015-04-28 16:35:58 +02:00
|
|
|
else
|
2017-05-19 00:04:08 +02:00
|
|
|
fprintf(fid,',name path=%d]', series_num);
|
2015-04-28 16:35:58 +02:00
|
|
|
end
|
2013-03-27 16:20:59 +01:00
|
|
|
end
|