diff --git a/doc/dynare.texi b/doc/dynare.texi index 7c9e838ee0944b6649250259614a9a100a0ae35b..b1e8bb0a1ec86d8caeae05b8c8c4a7132af5d92f 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -11322,7 +11322,7 @@ command. Default: @code{`!'} @end defmethod @anchor{addGraph} -@defmethod Report addGraph axisShape, data, graphDirName, graphName, graphSize, height, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, miscTikzAxisOptions, miscTikzPictureOptions, seriesToUse, shade, shadeColor, shadeOpacity, tickFontSize, title, titleFontSize, titleFormat, width, xlabel, ylabel, xAxisTight, xrange, xTicks, xTickLabels, xTickLabelAnchor, xTickLabelRotation, yAxisTight, yTickLabelFixed, yTickLabelPrecision, yTickLabelScaled, yTickLabelZeroFill, yrange, showZeroline, zeroLineColor +@defmethod Report addGraph axisShape, data, graphDirName, graphName, graphSize, height, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, miscTikzAxisOptions, miscTikzPictureOptions, seriesToUse, shade, shadeColor, shadeOpacity, tickFontSize, title, titleFontSize, titleFormat, width, writeCSV, xlabel, ylabel, xAxisTight, xrange, xTicks, xTickLabels, xTickLabelAnchor, xTickLabelRotation, yAxisTight, yTickLabelFixed, yTickLabelPrecision, yTickLabelScaled, yTickLabelZeroFill, yrange, showZeroline, zeroLineColor Adds a @code{Graph} to a @code{Section}. @optionshead @table @code @@ -11337,10 +11337,12 @@ to the left, right, bottom, and top of the graphed line(s). @code{`L'} means that there is an axis to the left and bottom of the graphed line(s). Default: @code{`box'} +@anchor{graphDirName} @item graphDirName, @code{STRING} The name of the folder in which to store this figure. Default: @code{tmpRepDir} +@anchor{graphName} @item graphName, @code{STRING} The name to use when saving this figure. Default: something of the form @code{graph_pg1_sec2_row1_col3.tex} @@ -11426,6 +11428,12 @@ the title and subtitles. Default: @code{TikZ default} @item width, @code{DOUBLE} The width of the graph, in inches. Default: @code{6.0} +@item writeCSV, @code{BOOLEAN} +Whether or not to write a CSV file with only the plotted data. The file will be +saved in the directory specified by @ref{graphDirName} with the same base name +as specified by @ref{graphName} with the ending @code{.csv}. Default: +@code{false} + @item xlabel, @code{STRING} The x-axis label. Default: @code{none} diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m index 7aa052514a9e85d3bf84c8fd24d128e07f6ab49f..4d73da534628a657db480721dcd9d9c058374cd9 100644 --- a/matlab/reports/@graph/graph.m +++ b/matlab/reports/@graph/graph.m @@ -85,6 +85,8 @@ o.height = 4.5; o.miscTikzPictureOptions = ''; o.miscTikzAxisOptions = ''; +o.writeCSV = false; + if nargin == 1 assert(isa(varargin{1}, 'graph'),['@graph.graph: with one arg you ' ... 'must pass a graph object']); @@ -139,7 +141,7 @@ assert(isint(o.yTickLabelPrecision), '@graph.graph: o.yTickLabelPrecision must b assert(islogical(o.yTickLabelFixed), '@graph.graph: yTickLabelFixed must be either true or false'); assert(islogical(o.yTickLabelZeroFill), '@graph.graph: yTickLabelZeroFill must be either true or false'); assert(islogical(o.yTickLabelScaled), '@graph.graph: yTickLabelScaled must be either true or false'); - +assert(islogical(o.writeCSV), '@graph.graph: writeCSV must be either true or false'); assert(ischar(o.shadeColor), '@graph.graph: shadeColor must be a string'); assert(ischar(o.zeroLineColor), '@graph.graph: zeroLineColor must be a string'); assert(any(strcmp(o.axisShape, {'box', 'L'})), ['@graph.graph: axisShape ' ... diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m index bd820c9e9117519e2e22c2801465c767c4e8c109..85b09d41d3c2b8b3efc923d8758132e9f495e76d 100644 --- a/matlab/reports/@graph/writeGraphFile.m +++ b/matlab/reports/@graph/writeGraphFile.m @@ -231,8 +231,25 @@ if o.showZeroline o.zeroLineColor, dd.ndat); end +if o.writeCSV + csvseries = dseries(); +end for i=1:ne o.series{i}.writeSeriesForGraph(fid, dd); + if o.writeCSV + csvseries = [csvseries ... + o.series{i}.data(dd).set_names([... + o.series{i}.data.name{:} '_' ... + o.series{i}.graphLegendName '_' ... + o.series{i}.graphLineColor '_' ... + o.series{i}.graphLineStyle '_' ... + num2str(o.series{i}.graphLineWidth) '_' ... + o.series{i}.graphMarker '_' ... + o.series{i}.graphMarkerEdgeColor '_' ... + o.series{i}.graphMarkerFaceColor '_' ... + num2str(o.series{i}.graphMarkerSize)]) ... + ]; + end if o.showLegend le = o.series{i}.getNameForLegend(); if ~isempty(le) @@ -240,6 +257,9 @@ for i=1:ne end end end +if o.writeCSV + csvseries.save(strrep(o.graphName, '.tex', ''), 'csv'); +end fprintf(fid, '\\end{axis}\n\\end{tikzpicture}%%'); if fclose(fid) == -1 error('@graph.writeGraphFile: closing %s\n', o.filename); diff --git a/tests/reporting/CountryGraphPage.m b/tests/reporting/CountryGraphPage.m index 6323649b29d5dd62f7833bfa8f99cb9bbd51ed61..d67bb28a1817449028275d9e1fe1553f6abeacf5 100644 --- a/tests/reporting/CountryGraphPage.m +++ b/tests/reporting/CountryGraphPage.m @@ -25,7 +25,8 @@ rep = rep.addGraph('title', 'Interest Rate', ... 'showZeroline', true, ... 'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ... 'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},... - 'xTickLabelRotation', 0); + 'xTickLabelRotation', 0, ... + 'writeCSV', true); rep = rep.addSeries('data', db_q{['RS_' countryAbbr]}, ... 'graphLineColor', 'blue', ... 'graphLineStyle', 'dashed', ...