Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

recessionplot

Overlay recession bands on a time series plot

Syntax

  • recessionplot
    example
  • recessionplot(Name,Value)
  • hBands = recessionplot(___)
    example

Description

example

recessionplot overlays shaded recession bands on a time series plot.

recessionplot(Name,Value) uses additional options specified by one or more Name,Value pairs.

example

hBands = recessionplot(___) returns a vector of handles to the recession bands, using any of the previous input arguments.

Examples

collapse all

Overlay recession bands on a plot of multiple time series.

Load data on credit defaults, and extract the predictor variables in the first four columns.

load Data_CreditDefaults
X0 = Data(:,1:4);
T0 = size(X0,1);

Convert the dates to serial date numbers, as required by recessionplot.

dates = datenum([dates,ones(T0,2)]);

Create a time series plot of the four credit default predictors.

figure;
plot(dates,X0,'LineWidth',2);
h = gca;
h.XTick = dates(1:2:end);
datetick('x','yyyy','keepticks')
xlabel 'Year';
ylabel 'Level';
axis tight;

Overlay recession bands corresponding to U.S. recessions reported by the National Bureau of Economic Research.

recessionplot

The plots shows that two recessions occurred within the range of the time series.

Overlay recession bands on a plot of multiple time series. Return the handles of the recession bands so you can change their color and transparency.

Load data on credit defaults, and extract the predictor variables in the first four columns.

load Data_CreditDefaults
X0 = Data(:,1:4);
T0 = size(X0,1);

Convert dates to serial date numbers, and then plot the four time series.

dates = datenum([dates,ones(T0,2)]);

figure;
plot(dates,X0,'LineWidth',2);
h = gca;
h.XTick = dates(1:2:end);
datetick('x','yyyy','keepticks')
xlabel 'Year';
ylabel 'Level';
axis tight

Overlay recession bands, returning the handles to the bands. Change the band color to red and increase the transparency.

hBands = recessionplot;
set(hBands,'FaceColor','r','FaceAlpha',0.4)

Input Arguments

collapse all

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'axes',h1 overlays recession bands on the axes identified by the handle h1

collapse all

Handle to axes displaying a time series plot, specified as the comma-separated pair consisting of 'axes' and an axes handle. The time series plot must have serial date numbers on the horizontal axis

Example: 'axes',h1

Recession data indicating the beginning and end of historical recessions, specified as the comma-separated pair consisting of 'recessions' and a numRecessions-by-2 matrix of serial date numbers. The first column indicates the beginning of the recession, and the second column indicates the end of the recession. The default recession data is the U.S. recession data in Data_Recessions.mat, reported by the National Bureau of Economic Research.

Output Arguments

collapse all

Handles to the recession bands, returned as a vector of handles.

More About

collapse all

Tips

  • recessionplot requires that you express dates on the horizontal axis of a time series plot as serial date numbers. To convert other date information to this format before plotting, use datenum.

  • Use the output handles to change the color and transparency of the recession bands by setting their FaceColor and FaceAlpha properties. This might be necessary to achieve satisfactory displays when working with certain monitors and projectors.

See Also

Introduced in R2012a

Was this topic helpful?