From 5899a19e797bed32d204a12b24a9f311d5999ccd Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Thu, 20 Feb 2014 16:24:37 +0100 Subject: [PATCH] reporting: change xTickLabels default to be first date, last date, and, if passed, the first date of the shade region. Accordingly, change the default of the tick rotation to be 0. --- doc/dynare.texi | 10 +++++++--- matlab/reports/@graph/graph.m | 2 +- matlab/reports/@graph/writeGraphFile.m | 21 ++++++++++++++------- tests/reporting/runDynareReport.m | 2 -- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index 7690ae9585..b371d9f80f 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -10836,6 +10836,7 @@ The names of the series contained in the @code{dseries} provided to the @ref{data} option. If empty, use all series provided to @ref{data} option. Default: @code{empty} +@anchor{shade} @item shade, @code{dates} The date range showing the portion of the graph that should be shaded. Default: @code{none} @@ -10876,18 +10877,21 @@ The boundary on the x-axis to display in the graph. Default: all @item xTicks, @code{NUMERICAL_VECTOR} Used only in conjunction with @ref{xTickLabels}, this option denotes the numerical position of the label along the x-axis. The positions -begin at @math{1}. Default: set by Matlab/Octave. +begin at @math{1}. Default: the indices associated with the first and +last dates of the @code{dseries} and, if passed, the index associated +with the first date of the @ref{shade} option. @anchor{xTickLabels} @item xTickLabels, @code{CELL_ARRAY_STRINGS} The labels to be mapped to the ticks provided by -@ref{xTicks}. Default: the dates of the @code{dseries} +@ref{xTicks}. Default: the first and last dates of the @code{dseries} +and, if passed, the date first date of the @ref{shade} option. @item xTickLabelAnchor, @code{STRING} Where to anchor the x tick label. Default: @code{`south'} @item xTickLabelRotation, @code{DOUBLE} -The amount to rotate the x tick labels by. Default: @code{45} +The amount to rotate the x tick labels by. Default: @code{0} @item yAxisTight, @code{BOOLEAN} Use a tight y axis. If false, uses pgfplots @code{enlarge y limits} to diff --git a/matlab/reports/@graph/graph.m b/matlab/reports/@graph/graph.m index cd1747d6ca..7b710e3fc2 100644 --- a/matlab/reports/@graph/graph.m +++ b/matlab/reports/@graph/graph.m @@ -66,7 +66,7 @@ o.showZeroline = false; o.graphSize = []; o.xTicks = []; o.xTickLabels = {}; -o.xTickLabelRotation = 45; +o.xTickLabelRotation = 0; o.xTickLabelAnchor = 'east'; o.width = 6; diff --git a/matlab/reports/@graph/writeGraphFile.m b/matlab/reports/@graph/writeGraphFile.m index 24b602ff0b..db44025b38 100644 --- a/matlab/reports/@graph/writeGraphFile.m +++ b/matlab/reports/@graph/writeGraphFile.m @@ -56,12 +56,19 @@ if isempty(o.xrange) else dd = o.xrange; end +stringsdd = strings(dd); fprintf(fid, '\\begin{axis}[%%\n'); % set tick labels if isempty(o.xTickLabels) - x = 1:1:dd.ndat; - xTickLabels = strings(dd); + if ~isempty(o.shade) + x1 = find(strcmpi(date2string(o.shade(1)), stringsdd)); + x = [1 x1 dd.ndat]; + xTickLabels = [stringsdd(1) stringsdd(x1) stringsdd(end)]; + else + x = [1 dd.ndat]; + xTickLabels = [stringsdd(1) stringsdd(end)]; + end fprintf(fid, 'xminorticks=true,\nyminorticks=true,\n'); else fprintf(fid,'minor xtick,\n'); @@ -69,11 +76,12 @@ else xTickLabels = o.xTickLabels; end fprintf(fid, 'xticklabels={'); -for i = 1:length(x) +xlen = length(x); +for i = 1:xlen fprintf(fid,'%s,',lower(xTickLabels{i})); end fprintf(fid, '},\nxtick={'); -for i = 1:length(x) +for i = 1:xlen fprintf(fid, '%d',x(i)); if i ~= length(x) fprintf(fid,','); @@ -159,9 +167,8 @@ for i=1:ne end if ~isempty(o.shade) - xTickLabels = strings(dd); - x1 = find(strcmpi(date2string(o.shade(1)), xTickLabels)); - x2 = find(strcmpi(date2string(o.shade(end)), xTickLabels)); + x1 = find(strcmpi(date2string(o.shade(1)), stringsdd)); + x2 = find(strcmpi(date2string(o.shade(end)), stringsdd)); assert(~isempty(x1) && ~isempty(x2), ['@graph.writeGraphFile: either ' ... date2string(o.shade(1)) ' or ' date2string(o.shade(end)) ' is not in the date ' ... 'range of data selected.']); diff --git a/tests/reporting/runDynareReport.m b/tests/reporting/runDynareReport.m index 7ae2f11246..4bdd4ffc75 100644 --- a/tests/reporting/runDynareReport.m +++ b/tests/reporting/runDynareReport.m @@ -239,8 +239,6 @@ rep = rep.addGraph('title', 'Equilibrium World Real Food Price', ... 'xrange', prange, ... 'shade', srange, ... 'showLegend', true, ... - 'xTicks', [1,5,10,15,find(srange(1)==prange),length(prange)], ... - 'xTickLabels',{startpoint{:},'2008Q1','2009Q2','2010Q3',shaded{:}, endpoint{:}},... 'xTickLabelRotation', 0); rep = rep.addSeries('data', db_q{'LRPFOOD_BAR_WORLD'}, ... 'graphLineColor', 'blue', ... -- GitLab