From 263c84e98567eece88a0cac1a76a291c85457303 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Wed, 13 Mar 2013 15:38:24 +0100 Subject: [PATCH] reporting: xrange & yrange --- matlab/reporting/@graph/createGraph.m | 41 ++++++++++++++------------- matlab/reporting/@graph/graph.m | 4 ++- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/matlab/reporting/@graph/createGraph.m b/matlab/reporting/@graph/createGraph.m index 605b0e9243..763e3f3486 100644 --- a/matlab/reporting/@graph/createGraph.m +++ b/matlab/reporting/@graph/createGraph.m @@ -51,30 +51,35 @@ end %set(h, 'units', 'normalized', 'outerposition', [0 0 1 1]); if strcmpi(o.seriestouse, 'all') - data = o.data.data; + ds = o.data; else - data = o.data{o.seriestouse{:}}.data; + ds = o.data{o.seriestouse{:}}; end -x=[1:1:o.data.nobs]; -xlabels=getDatesCellStringArray(o.data.time); +if ~strcmp(o.xrange, 'all') + dd1 = dynDate(o.xrange{1}); + dd2 = dynDate(o.xrange{2}); + ds = ds(dd1:dd2); +end +data = ds.data; + +x = 1:1:ds.nobs; +xlabels = getDatesCellStringArray(ds.time); plot(x, data); +if ~strcmp(o.yrange, 'all') + ylim([o.yrange{:}]); +end + if ~isempty(o.shade) - x1 = strmatch(lower(o.shade{1}), xlabels, 'exact'); - x2 = strmatch(lower(o.shade{2}), xlabels, 'exact'); + x1 = find(strcmp(o.shade{1}, xlabels)); + x2 = find(strcmp(o.shade{2}, xlabels)); + assert(~isempty(x1) && ~isempty(x2), ['@graph.createGraph: either ' ... + o.shade{1} ' or ' o.shade{2} 'is not in the date ' ... + 'range of data selected.']); yrange = get(gca, 'YLim'); - if isempty(x1) - error(['@graph.createGraph: ' o.shade{1} ' not in date range of ' ... - 'provided data']); - end - if isempty(x2) - error(['@graph.createGraph: ' o.shade{2} ' not in date range of ' ... - 'provided data']); - end - % From ShadePlotForEmpahsis (Matlab Exchange) % use patch bc area doesn't work with matlab2tikz patch([repmat(x1, 1, 2) repmat(x2, 1, 2)], [yrange fliplr(yrange)], ... @@ -85,11 +90,7 @@ set(gca,'XTick', x); set(gca,'XTickLabel', xlabels); if o.legend - if strcmpi(o.seriestouse, 'all') - lh = legend(o.data.name); - else - lh = legend(o.seriestouse{:}); - end + lh = legend(ds.name); set(lh, 'orientation', o.legend_orientation); set(lh, 'Location', o.legend_location); set(lh, 'FontSize', o.legend_font_size); diff --git a/matlab/reporting/@graph/graph.m b/matlab/reporting/@graph/graph.m index 1836ac9c3c..4c9d8c14d1 100644 --- a/matlab/reporting/@graph/graph.m +++ b/matlab/reporting/@graph/graph.m @@ -44,7 +44,9 @@ o.footnote = ''; o.figname = ''; o.data = ''; o.seriestouse = 'all'; -o.shade = ''; %{1959q1:1964q4} +o.shade = ''; +o.xrange = 'all'; +o.yrange = 'all'; o.grid = true; -- GitLab