Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dynare
reporting
Commits
4d497e1a
Commit
4d497e1a
authored
Apr 27, 2015
by
Houtan Bastani
Browse files
add possibility to create fan charts
parent
1da03c6c
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/@graph/writeGraphFile.m
View file @
4d497e1a
...
...
@@ -239,7 +239,7 @@ if o.writeCSV
csvseries
=
dseries
();
end
for
i
=
1
:
ne
o
.
series
{
i
}
.
writeSeriesForGraph
(
fid
,
dd
);
o
.
series
{
i
}
.
writeSeriesForGraph
(
fid
,
dd
,
i
);
if
o
.
writeCSV
csvseries
=
[
csvseries
...
o
.
series
{
i
}
.
data
(
dd
)
.
set_names
([
...
...
...
src/@report/write.m
View file @
4d497e1a
...
...
@@ -52,7 +52,7 @@ if isoctave && isempty(regexpi(computer, '.*apple.*', 'once'))
fprintf
(
fid
,
'\\usepackage[utf8x]{inputenc}\n'
);
fprintf
(
fid
,
'\\usepackage{gnuplot-lua-tikz}\n'
);
end
fprintf
(
fid
,
'\\usepgfplotslibrary{fillbetween}\n'
);
fprintf
(
fid
,
'\\definecolor{LightCyan}{rgb}{0.88,1,1}\n'
);
fprintf
(
fid
,
'\\definecolor{Gray}{gray}{0.9}\n'
);
if
o
.
showDate
...
...
src/@report_series/report_series.m
View file @
4d497e1a
...
...
@@ -14,7 +14,7 @@ function o = report_series(varargin)
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2013-201
4
Dynare Team
% Copyright (C) 2013-201
5
Dynare Team
%
% This file is part of Dynare.
%
...
...
@@ -35,6 +35,9 @@ o = struct;
o
.
data
=
''
;
o
.
graphFanShadeColor
=
''
;
o
.
graphFanShadeOpacity
=
50
;
o
.
graphLegendName
=
''
;
o
.
graphLineColor
=
'black'
;
...
...
@@ -104,4 +107,4 @@ end
% Create report_series object
o
=
class
(
o
,
'report_series'
);
end
\ No newline at end of file
end
src/@report_series/writeSeriesForGraph.m
View file @
4d497e1a
function
o
=
writeSeriesForGraph
(
o
,
fid
,
xrange
)
%function o = writeSeriesForGraph(o, fid, xrange)
function
o
=
writeSeriesForGraph
(
o
,
fid
,
xrange
,
series_num
)
%function o = writeSeriesForGraph(o, fid, xrange
, series_num
)
% Print a TikZ line
%
% INPUTS
% 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
%
% OUTPUTS
% NONE
...
...
@@ -80,10 +81,14 @@ assert(isempty(o.graphHline) || isnumeric(o.graphHline), ...
% Zero tolerance
assert
(
isfloat
(
o
.
zeroTol
),
'@report_series.write: zeroTol must be a float'
);
% 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'
);
%% graphVline && graphHline
if
~
isempty
(
o
.
graphVline
)
fprintf
(
fid
,
'%%Vertical Line\n\\begin{pgfonlayer}{axis lines}\n\\draw'
);
writeLineOptions
(
o
,
fid
);
writeLineOptions
(
o
,
fid
,
series_num
);
stringsdd
=
strings
(
xrange
);
x
=
find
(
strcmpi
(
date2string
(
o
.
graphVline
),
stringsdd
));
fprintf
(
fid
,
[
'(axis cs:%d,\\pgfkeysvalueof{/pgfplots/ymin}) -- (axis '
...
...
...
@@ -92,7 +97,7 @@ if ~isempty(o.graphVline)
end
if
~
isempty
(
o
.
graphHline
)
fprintf
(
fid
,
'%%Horizontal Line\n\\begin{pgfonlayer}{axis lines}\n\\addplot'
);
writeLineOptions
(
o
,
fid
);
writeLineOptions
(
o
,
fid
,
series_num
);
fprintf
(
fid
,
[
'coordinates {(\\pgfkeysvalueof{/pgfplots/xmin},%f)'
...
'(\\pgfkeysvalueof{/pgfplots/xmax},%f)};\n\\end{pgfonlayer}\n'
],
...
o
.
graphHline
,
o
.
graphHline
);
...
...
@@ -111,15 +116,24 @@ end
thedata
=
setDataToZeroFromZeroTol
(
o
,
ds
);
fprintf
(
fid
,
'%%series %s\n\\addplot'
,
o
.
data
.
name
{:});
writeLineOptions
(
o
,
fid
);
writeLineOptions
(
o
,
fid
,
series_num
);
fprintf
(
fid
,
'\ntable[row sep=crcr]{\nx y\\\\\n'
);
for
i
=
1
:
ds
.
dates
.
ndat
fprintf
(
fid
,
'%d %f\\\\\n'
,
i
,
thedata
(
i
));
end
fprintf
(
fid
,
'};\n'
);
% For Fan charts
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] fill between[of=%d and %d];\n'
,
...
o
.
graphFanShadeColor
,
o
.
graphFanShadeOpacity
,
series_num
,
series_num
-
1
);
end
end
function
writeLineOptions
(
o
,
fid
)
function
writeLineOptions
(
o
,
fid
,
series_num
)
if
o
.
graphBar
fprintf
(
fid
,
'[ybar,ybar legend,color=%s,fill=%s,line width=%fpt'
,
...
o
.
graphBarColor
,
o
.
graphBarFillColor
,
o
.
graphBarWidth
);
...
...
@@ -141,5 +155,5 @@ end
if
~
isempty
(
o
.
graphMiscTikzAddPlotOptions
)
fprintf
(
fid
,
',%s'
,
o
.
graphMiscTikzAddPlotOptions
);
end
fprintf
(
fid
,
'
]'
);
fprintf
(
fid
,
'
,name path=%d]'
,
series_num
);
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment