 TimeSeriesAnalysis - Maple Programming Help

Home : Support : Online Help : Statistics and Data Analysis : Time Series Analysis Package : TimeSeriesAnalysis/TimeSeriesPlot

TimeSeriesAnalysis

 TimeSeriesPlot
 display time series data

 Calling Sequence TimeSeriesPlot(ts1) TimeSeriesPlot(ts1, ts2, [ts3, opt1, opt2], ts4, opt3, opt4)

Parameters

 ts1, ts2, ts3, ts4 - TimeSeries objects opt1, opt2, opt3, opt4 - plot options of the form optionname = value; options not inside lists such as opt3 and opt4 can also have the form split = value (see below)

Description

 • The TimeSeriesPlot command is used for visualizing time series data. It can show multiple data sets of different time series with one invocation, possibly with different plot options for different time series. Moreover, the data sets can be shown in a single plot or they can be split into multiple plots.
 • The first calling sequence above creates a plot with all data sets from a single time series in it, and default plot options.
 • The second calling sequence shows an example of how you can plot multiple time series. You do this by submitting a sequence consisting of time series and/or lists, in arbitrary order. If lists are included, then the first element of each such list should be a time series, and all other elements should be plot options: these plot options apply only to the time series in the list. In addition, more plot options can be given after all time series; these options apply to all time series. For example, to change the size of a plot, you can use the size option; the default used for time series plots is $\mathrm{size}=\left[0.75,0.35\right]$. If an option is given both outside of lists and in a list with a time series, then for that time series the option specified in the list takes precedence.

Specifying Colors

 • If you want all curves in the resulting plot to be the same color, you can use the color option as specified on the help page for plot options. Similarly, if you want all curves of a time series to be the same color, you can put that time series in a list and add the color option to that list.
 • You can also specify different colors as a list:
 – If you specify colors as a list for a color option occurring outside a list, the colors are applied to all data sets of all time series. In this case, the number of colors specified must be at least the number of data sets occurring in all time series given.
 – Alternatively, if you specify colors as a list for a color option included in a list with a time series, then the colors are applied to the data sets of this time series only. In this case, the number of colors specified must be at least the number of data sets occurring in the time series to which the option applies.
 • The TimeSeriesPlot command also supports using a range of colors for either all data sets in one time series, or all data sets processed by the command. This is done with the option color = C1 .. C2, where C1 and C2 are specifications of colors such that color = C1 and color = C2 are valid color options. Such an option can be applied to the whole command, or to an individual time series. This feature uses the ColorTools[Gradient] command.

The split Option

 • The split option can be used to split the display of data sets into several plots, displayed as an array plot. There are several ways this can be specified:
 • split = separate
 This option makes a separate plot in the plot array for each data set.
 • split = pertimeseries
 This option makes a separate plot for each time series, containing all data sets from that time series.
 • split = together
 This option makes a single plot containing all data sets from all time series.
 • split = automatic
 This option behaves like split = together, except for time series resulting from the TimeSeriesAnalysis[Decomposition] command. Such time series are separated out from the rest and all their data sets get a separate plot.
 • split = [spec1, spec2, ...]
 Using a list for the value of the split option, you can fully customize how the data sets are distributed over plots. Each item in the list is a specification for a single plot in the array plot that is generated. You can use several types of items in these lists:
 – The first possibility is a list [ts, is1, is2, ...] where the first element is one of the time series you have specified, and the subsequent elements are either positive integers or strings. These elements select data sets from the time series: a positive integer is1 selects the data set in the is1th column of ts; a string is2 selects the data set with header is2. The result is to select all of the data sets given by these integers and/or strings.
 – The second possibility is a time series ts. This selects all data sets from this time series; it is equivalent to the list [ts, 1, 2, ..., k], where k is the number of data sets in ts.
 – The final possibility is a set {e1, e2, ...}, where each of element is either a list or a time series as explained in the previous two bullet points; this represents all of the data sets selected by each of e1, e2, and so on.
 • An example would be TimeSeriesPlot(ts1, ts2, ts3, split = [ts1, [ts2, 2, 3], {[ts2, 1], ts3}]), where ts2 is a time series with at least three data sets. This would split the data sets into three plots: one for all data sets in ts1, one for the second and third data set in ts2, and one for the first data set in ts2 and all data sets in ts3.

Examples

 > $\mathrm{with}\left(\mathrm{TimeSeriesAnalysis}\right):$

A basic example.

 > $\mathrm{ts1}≔\mathrm{TimeSeries}\left(\left[0.29,0.66,1.22,0.69,0.18,0.31,1.94,0.11,1.72\right],\mathrm{frequency}=\mathrm{monthly},\mathrm{header}="A",\mathrm{enddate}="2013-08"\right)$
 ${\mathrm{ts1}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {A}\\ {\mathrm{9 rows of data:}}\\ {\mathrm{2012-12-01 - 2013-08-01}}\end{array}\right]$ (1)
 > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts1}\right)$ Using plot options.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts1},\mathrm{color}=\mathrm{red},\mathrm{thickness}=3\right)$ Because there is only one time series, in this case it would be the same to specify these plot options in a list together with the time series.

 > $\mathrm{TimeSeriesPlot}\left(\left[\mathrm{ts1},\mathrm{color}=\mathrm{red},\mathrm{thickness}=3\right]\right)$ We add two more time series with several data sets.

 > $\mathrm{ts2}≔\mathrm{TimeSeries}\left(\left[\left[5.89,7.38,6.45,6.05,5.61,6.44,5.79,4.84,4.08,3.90,3.75,3.67,5.10,4.36,3.42,3.15,3.72,3.01,2.33,2.35,1.45,0.92,0.54,1.24,1.39\right],\left[1.20,0.12,1.47,0.36,1.84,1.30,4.94,0.77,0.55,0.25,0.03,0.31,0.90,1.85,0.66,2.83,0.38,3.66,6.85,0.80,0.89,0.45,0.91,1.71,1.81\right]\right],\mathrm{frequency}=\mathrm{weekly},\mathrm{headers}=\left["B","C"\right],\mathrm{enddate}="2013-07-24"\right)$
 ${\mathrm{ts2}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{B, C}}\\ {\mathrm{25 rows of data:}}\\ {\mathrm{2013-02-06 - 2013-07-24}}\end{array}\right]$ (2)
 > $\mathrm{ts3}≔\mathrm{TimeSeries}\left(\left[\left[102.,137.,113.,115.,146.,110.,116.,106.,107.,108.,115.,125.,143.,124.,111.,107.,124.,130.,101.,106.,104.,139.,140.,165.,142.,114.,101.,197.,113.,127.\right],\left[128.,125.,122.,115.,113.,107.,110.,106.,99.2,93.2,86.7,95.6,90.2,85.0,78.9,75.7,70.2,66.2,79.5,74.6,76.2,73.2,69.5,67.1,68.0,86.3,81.3,75.0,76.5,86.0\right],\left[3.15,2.44,6.64,10.7,12.8,11.6,10.9,9.66,13.8,14.1,13.2,14.2,13.2,13.7,13.5,12.7,11.4,11.8,10.6,11.9,10.7,9.69,9.36,8.95,10.6,9.77,9.45,8.26,9.25,8.57\right]\right],\mathrm{frequency}=\mathrm{weekly},\mathrm{headers}=\left["D","E","F"\right],\mathrm{enddate}="2013-08-10"\right)$
 ${\mathrm{ts3}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{D, E, F}}\\ {\mathrm{30 rows of data:}}\\ {\mathrm{2013-01-19 - 2013-08-10}}\end{array}\right]$ (3)

By default, these time series will all be shown in a single plot.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts1},\mathrm{ts2},\mathrm{ts3}\right)$ Because the quantities differ by orders of magnitude, this is not particularly useful. It is better to split the data sets into two plots. All data sets in time series $\mathrm{ts1}$ and $\mathrm{ts2}$, and data set $"F"$ from time series $\mathrm{ts3}$, have smaller values, whereas data sets $"D"$ and $"E"$ from time series $\mathrm{ts3}$ have larger values.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts1},\mathrm{ts2},\mathrm{ts3},'\mathrm{split}=\left[\left\{\mathrm{ts1},\mathrm{ts2},\left[\mathrm{ts3},"F"\right]\right\},\left\{\left[\mathrm{ts3},"D","E"\right]\right\}\right]'\right)$  We can make it clearer which data set comes from which time series by specifying colors. We specify the colors for $\mathrm{ts2}$ and $\mathrm{ts3}$ explicitly for the given time series by including it in the list, and specify that all other time series (in this case $\mathrm{ts1}$) are colored red by including a color option outside these lists.

For the split option, this time we use numbers to specify the data sets in $\mathrm{ts3}$, to the same effect as using strings before.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts1},\left[\mathrm{ts2},'\mathrm{color}'=\left["LightGreen","LightBlue"\right]\right],\left[\mathrm{ts3},'\mathrm{color}'="Purple".."Brown"\right],'\mathrm{color}=\mathrm{red}','\mathrm{split}=\left[\left\{\mathrm{ts1},\mathrm{ts2},\left[\mathrm{ts3},3\right]\right\},\left\{\left[\mathrm{ts3},1,2\right]\right\}\right]'\right)$  Alternatively, we can specify all of the colors for all of the data sets in a single list.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts1},\mathrm{ts2},'\mathrm{color}'=\left["Red","Green","Blue"\right]\right)$ We can split these three data sets into three plots, or group them per time series.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts1},\mathrm{ts2},'\mathrm{split}=\mathrm{separate}'\right)$   > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts1},\mathrm{ts2},'\mathrm{split}=\mathrm{pertimeseries}'\right)$  If a forecast and several confidence intervals are submitted, and the split option is not used (or equivalently, you use split = automatic), they are generally displayed in a single plot. An example follows.

 > $\mathrm{ts3e}≔\mathrm{ts3}\left[..,"E"\right]$
 ${\mathrm{ts3e}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {E}\\ {\mathrm{30 rows of data:}}\\ {\mathrm{2013-01-19 - 2013-08-10}}\end{array}\right]$ (4)
 > $\mathrm{model}≔\mathrm{ExponentialSmoothingModel}\left(\mathrm{ts3e}\right)$
 ${\mathrm{TimeSeriesAnalysis}}{:-}{\mathrm{ExponentialSmoothingModel}}{}\left({\mathrm{errors}}{=}\left\{{"A"}\right\}{,}{\mathrm{trend}}{=}\left\{{"N"}\right\}{,}{\mathrm{seasonal}}{=}\left\{{"N"}\right\}{,}{\mathrm{α}}{=}{0.9936889232395577}{,}{\mathrm{β}}{=}{0.}{,}{\mathrm{γ}}{=}{0.}{,}{\mathrm{φ}}{=}{1.}{,}{\mathrm{period}}{=}{1}{,}{\mathrm{l0}}{=}{127.98185718469705}{,}{\mathrm{b0}}{=}{0.}{,}{s}{=}\left(\left[\begin{array}{c}0.0\end{array}\right]\right){,}{\mathrm{σ}}{=}{6.351805227415049}{,}{\mathrm{constraints}}{=}{"both"}\right)$ (5)
 > $\mathrm{cis}≔\mathrm{Forecast}\left(\mathrm{model},\mathrm{ts3e},4,\mathrm{output}=\mathrm{confidenceintervals}\left(80,95\right)\right)$
 ${\mathrm{cis}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{E \left(forecast - 2 percentile\right), ..., E \left(forecast - 98 percentile\right)}}\\ {\mathrm{4 rows of data:}}\\ {\mathrm{2013-08-16 - 2013-09-06}}\end{array}\right]$ (6)
 > $\mathrm{TimeSeriesPlot}\left(\mathrm{ts3e},\mathrm{cis}\left[..,3\right],\left[\mathrm{cis}\left[..,\left[1,2,4,5\right]\right],'\mathrm{color}=\mathrm{blue}..\mathrm{green}'\right],'\mathrm{color}=\mathrm{red}'\right)$ A decomposition, however, is shown in separate plots by default.

 > $\mathrm{dc}≔\mathrm{Decomposition}\left(\mathrm{model},\mathrm{ts3e}\right)$
 ${\mathrm{dc}}{≔}\left[\begin{array}{c}{\mathrm{Time series}}\\ {\mathrm{E \left(residuals\right), E \left(level\right)}}\\ {\mathrm{30 rows of data:}}\\ {\mathrm{2013-01-19 - 2013-08-10}}\end{array}\right]$ (7)
 > $\mathrm{TimeSeriesPlot}\left(\mathrm{dc}\right)$  To show the curves together, use split = together.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{dc},'\mathrm{split}=\mathrm{together}'\right)$ If we plot all these items together, the decomposition will be split out, but the other elements will be shown together.

 > $\mathrm{TimeSeriesPlot}\left(\mathrm{dc},\mathrm{ts3e},\mathrm{cis}\left[..,3\right],\left[\mathrm{cis}\left[..,\left[1,2,4,5\right]\right],'\mathrm{color}=\mathrm{blue}..\mathrm{green}'\right],'\mathrm{color}=\mathrm{red}'\right)$   > 

Compatibility

 • The TimeSeriesAnalysis[TimeSeriesPlot] command was introduced in Maple 18.