diff --git a/matlab/reporting/@graph/createGraph.m b/matlab/reporting/@graph/createGraph.m index 605b0e9243274792030d3ff7b7b82ba0bacb38b8..763e3f3486a4040c5f6f0183555b0c553d3798e1 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 1836ac9c3c25bb84463afcd1900cc412098f0a45..4c9d8c14d1abbd4d37d1e67da9db45c3fab8a0ac 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;