9. Plotting tools
RISE ships a number of plotting helpers that fall into three groups:
Time-series plotters – methods on the
tsclass (plot,fanchart,plot_decomp) and the corresponding standalone routines that consume their output.Model plotters – one-call convenience methods on
dsge/ VAR objects (quick_irfs,quick_plots,plot_probabilities,plot_data_against_probabilities).Decorations and layout – shaded recession bands, super-labels across subplot grids, x-tick rotation, multi-panel layout helpers, date-tick handling.
Plus a save-figure utility and the default figure / print settings
applied automatically by rise_startup.
9.1. The myplot wrapper
utils.plot.myplot is the central plotting routine that every
ts-aware method calls into (ts.plot, ts.bar, ts.area,
ts.errorbar, …). It wraps an arbitrary plot function and adds:
automatic handling of
tsinputs (multi-column, multi-page);date-aware x-axis (frequency-specific tick labels via
plot_specs);optional date-range filtering (pass a
datesrange as the first positional argument);log-scale toggles and other RISE-specific options.
The user rarely calls myplot directly; it surfaces through ts
methods. Knowing it exists explains why ts.plot(...) accepts
extras that bare plot does not.
9.2. Time-series plotters
9.2.1. Fan charts
Two-step process:
Build the fan data from a
tsobject that holds either pages or columns (not both):data = fanchart(myts, ci);
ciis a vector of confidence levels in[0, 1]or[0, 100]. The returned struct has fieldsci,median,variance,quantiles,prob_index,probs.Plot it:
plot_fanchart(data) plot_fanchart(data, MainColor) plot_fanchart(data, MainColor, nticks) hh = plot_fanchart(...)
MainColoraccepts a single-character color code ('c','b','g','r','m','k','w'), an RGB triplet, or'nb'(the default; assumes exactly 4 quantile bands).nticksis the number of x-axis ticks (default8).
9.2.2. Decomposition bar plots
plot_decomp stacks positive and negative contributions as bars
and overlays the total as a line. The ts-method form and the
standalone form coexist:
plot_decomp(ts1, ..., 'Name', Value, ...)
plot_decomp(xrange, ts1, ..., 'Name', Value, ...)
The optional xrange (e.g. rq(2020,1):rq(2022,4)) restricts the
plot to a date window. Each ts argument has one column per
component; the total line is the sum of the columns. Name-value pairs
are forwarded to plot.
9.3. Model plotters
These take a solved model object as input and produce publication-shaped multi-panel figures with sensible defaults.
9.3.1. quick_irfs
hdl = quick_irfs(m, myirfs, var_list, shock_list, r0c0, xrange, suplab, leGend)
Lays out impulse-response panels: one figure per shock, one subplot per
variable. myirfs is the structure returned by irf; var_list
and shock_list filter the rows and figures; r0c0 = [rows, cols]
controls the grid (default [4, 4]); xrange restricts horizons;
suplab adds a super-label across the grid; leGend adds a legend.
9.3.2. quick_plots
Generic counterpart for arbitrary post-solve series (forecasts,
simulations, historical decompositions). Same layout idea, same set of
optional arguments (var_list, fig_title, r0c0, …). Two
forms:
quick_plots(m, batch, ...)– as a@genericmethod.utils.plot.quick_plots(description, batch, ...)– standalone with an explicitdescriptionstruct rather than a model.
9.3.3. Smoothed probabilities
plot_probabilities(model)
plot_probabilities(model, specs, stateList, regimeList, shadeInfo, description)
For Markov-switching dsge / VAR models. Plots the smoothed
probabilities of states (stateList) and / or regimes
(regimeList). specs = [rows, cols] sets the grid; shadeInfo
is an optional function handle (typically wrapping shade) that adds
shaded bands; description is an optional struct overriding labels.
plot_data_against_probabilities(model, type, specs, shadeInfo, description)
Overlays the observed data against the smoothed state or regime
probabilities. type is 'state' or 'regime', optionally with
a variable list.
9.4. Decorations and layout
9.4.1. shade
shade(start_finish)
shade(start_finish, color)
shade(start_finish, color, fig)
Adds shaded vertical bands to an existing plot. start_finish is
either an n x 2 matrix of date pairs or a logical ts whose
true intervals define the shaded periods. Default color is light
gray [211, 211, 211] / 255. The shading respects current y-limits
and sits behind plotted data; works on tiled and multi-axes figures. An
interval that begins before the visible range but reaches into it is
shaded from the left edge of the axes (and one that ends after the visible
range up to the right edge); an interval wholly outside is left out. The
hold state of the axes, and with two y axes the side in use, are left as
they were: the bands are drawn on the side in use, with its limits.
9.4.2. recession_dates
r = recession_dates(F)
NBER recession periods at frequency F ('D', 'W', 'M',
'Q', 'H', 'Y'; default 'Q'). Returns a cell array of
[start, end] date pairs ready to feed into shade. A recession of a
single period, and one that is still going on at the end of the sample, is a
pair like any other (start and end the same period for the first).
9.4.3. sup_label
[ax, h] = sup_label(text, whichLabel, supAxes)
ax = sup_label(text, whichLabel, supAxes)
Places a single title / xlabel / ylabel spanning a group of
subplots (whichLabel selects which). Returns handles to the
super-axis (and optionally to the text). Lifted from Ben Barrowes’
suplabel on File Exchange, with minor RISE-specific tweaks.
9.4.4. xrotate
xrotate() % default 90 degrees
xrotate(angle) % numeric or string
Rotates x-axis tick labels for every Cartesian axis in the current figure. Skips polar / geographic axes.
9.4.5. number_of_rows_and_columns_in_figure
[Remains, r, c] = number_of_rows_and_columns_in_figure(fig, nvar, r0, c0)
Tiles nvar variables across the current figure with up to r0
rows and c0 columns per page. Remains is what didn’t fit on
this page, intended to be passed back in a loop until empty.
9.4.6. plot_specs
pp = plot_specs(serial_dates, nticks)
Computes x-axis values, tick locations and labels, and x-limits from
a serial-date vector. Used internally by myplot to honor
frequency-specific date formatting; useful directly only when bypassing
myplot to drive a non-RISE plot routine off RISE dates.
9.5. Saving figures
9.5.1. save_figure
save_figure(figHandle,baseName)
save_figure(figHandle,baseName,resDir)
save_figure(figHandle,baseName,resDir,Name=Value)
Writes a figure to disk in any combination of .fig, .png,
.pdf, .svg, .jpeg, working on a temporary copy so the
original figure is left untouched. By default applies a “tight” layout
pass that minimizes whitespace around plotted content – the result is
suited to direct inclusion in LaTeX / Beamer documents without manual
trimming. baseName may include a path (in which case resDir is
ignored); resDir defaults to the current folder. The options are
name-value arguments: formats, a cell of formats among 'fig',
'png', 'pdf', 'svg' and 'jpeg' (default
{'fig','png'}); resolution in dots per inch for the raster
formats (default 300); tight (default true); closefig
(default false); and fontSize, titleScale and
labelScale to enlarge the text. A format is never given
positionally: in save_figure(fig,'chart','pdf') the third
argument is the folder. A format that cannot be written is a warning, and
the message that follows names the formats that were written; when none can
be written the call is the error save_figure:nothingSaved. The figure is
closed (closefig) only when every format asked for was written. With an
output, files = save_figure(...) returns the files written.
9.6. Default figure and print settings
rise_startup configures MATLAB’s root-level figure paper properties
so that any figure later printed picks up landscape A4 with a sensible
content box. The relevant assignments:
set(0, 'DefaultFigurePaperOrientation', 'landscape');
set(0, 'DefaultFigurePaperType', 'A4');
set(0, 'DefaultFigurePaperUnits', 'centimeters');
set(0, 'DefaultFigurePaperPositionMode','manual');
set(0, 'DefaultFigurePaperPosition', [3.56 2.03 22.56 16.92]);
These are root defaults; they propagate to every figure created after
rise_startup unless explicitly overridden on the figure itself.
rise_exit restores them to MATLAB factory values.
Two practical consequences:
print(fig, '-dpdf', ...)produces a landscape PDF at the configured size by default. No per-figure paper setup is needed before printing.save_figure(fig,'chart','results',formats={'pdf'})does not use that page: by default (tight) it sets the page to the box around the axes, so the PDF has the size of the figure.If you want a different paper geometry, override on the figure (
set(fig, 'PaperPosition', ...)) rather than on the root – per-figure settings take precedence.