From 82e45f67aa9f71eebe9da3a97c04dc561f0fe840 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Mon, 22 Jul 2013 13:17:26 -0400 Subject: [PATCH] reporting: @graph: new option xTickLabels --- doc/dynare.texi | 6 +++++- matlab/reports/@graph/createGraph.m | 20 ++++++++++++-------- matlab/reports/@graph/graph.m | 4 +++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 2bb303b7e..f16cf8736 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -8240,7 +8240,7 @@ command. Default: @code{`!'} @end table @end defmethod -@defmethod Report addGraph data, figname, graphSize, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, seriesToUse, shade, shadeColor, shadeOpacity, title, xlabel, ylabel, xrange, yrange, showZeroline +@defmethod Report addGraph data, figname, graphSize, showGrid, showLegend, showLegendBox, legendLocation, legendOrientation, legendFontSize, seriesToUse, shade, shadeColor, shadeOpacity, title, xlabel, ylabel, xrange, xTickLabels, yrange, showZeroline Adds a @code{Graph} to a @code{Section}. @optionshead @table @code @@ -8309,6 +8309,10 @@ The y-axis label. Default: @code{none} @item xrange, @code{dynDates} The boundary on the x-axis to display in the graph. Default: all +@item xTickLabels, @code{CELL_ARRAY_STRINGS} +The labels to use for the xticks in the graph. Default: the dates of +the @code{dynSeries} + @item yrange, @code{NUMERICAL_VECTOR} The boundary on the y-axis to display in the graph, represented as a @code{NUMERICAL_VECTOR} of size @math{2}, with the first entry less diff --git a/matlab/reports/@graph/createGraph.m b/matlab/reports/@graph/createGraph.m index 9788521ca..48f1c3771 100755 --- a/matlab/reports/@graph/createGraph.m +++ b/matlab/reports/@graph/createGraph.m @@ -98,15 +98,19 @@ if ~isempty(o.shade) set(gca, 'children', children); end -xticks = get(gca, 'XTick'); -xTickLabels = cell(1, length(xticks)); -for i=1:length(xticks) - if xticks(i) >= x(1) && ... - xticks(i) <= x(end) - xTickLabels{i} = xlabels{xticks(i)}; - else - xTickLabels{i} = ''; +if isempty(o.xTickLabels) + xticks = get(gca, 'XTick'); + xTickLabels = cell(1, length(xticks)); + for i=1:length(xticks) + if xticks(i) >= x(1) && ... + xticks(i) <= x(end) + xTickLabels{i} = xlabels{xticks(i)}; + else + xTickLabels{i} = ''; + end end +else + xTickLabels = o.xTickLabels; end set(gca, 'XTickLabel', xTickLabels); diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m index 62565770f..72273c7f9 100644 --- a/matlab/reports/@graph/graph.m +++ b/matlab/reports/@graph/graph.m @@ -60,6 +60,7 @@ o.legendFontSize = 8; o.showZeroline = false; o.graphSize = []; +o.xTickLabels = {}; if nargin == 1 assert(isa(varargin{1}, 'graph'),['@graph.graph: with one arg you ' ... @@ -132,7 +133,8 @@ assert(isempty(o.seriesToUse) || iscellstr(o.seriesToUse), ['@graph.graph: ' ... assert(isempty(o.graphSize) || ((isfloat(o.graphSize) && length(o.graphSize) == 2)),... ['@graph.graph: graphSize is specified as an array with two float ' ... 'entries, [width height]']); - +assert(iscellstr(o.xTickLabels), ... + '@graph.graph: xTickLabels must be a cell array of strings'); % using o.seriesToUse, create series objects and put them in o.seriesElements if ~isempty(o.data) if isempty(o.seriesToUse) -- GitLab