Skip to Main Content Skip to Search
Product Documentation

plot - Class: timeseries

Plot time series

Syntax

plot(ts)
plot(tsc.tsname)
plot(ts,linespec)
plot(tsc.tsname,linespec)
plot(ts,Name, Value)
plot(tsc.tsname,Name, Value)

Description

plot(ts) plots the timeseries data ts against time and interpolates values between samples by using either zero-order-hold ('zoh') or linear interpolation (the default). The plot displays in the current axes. MATLAB creates a title and axes, if none exists.

plot(tsc.tsname) plots the timeseries object, tsname that is part of the tscollection, tsc.

plot(ts,linespec) plots the timeseries data using a line graph and applies the specified linespec to lines, markers, or both.

plot(tsc.tsname,linespec) plots the timeseries object that is part of a timeseries collection as a line graph and applies the specified linespec to lines, markers, or both.

plot(ts,Name, Value) plots a line graph of the time series data using the values specified for lineseries properties.

plot(tsc.tsname,Name, Value) plots a line graph of the timeseries object that is part of the specified timeseries collection using the values specified for lineseries properties.

Tips

Input Arguments

ts

A timeseries object.

tsc

A tscollection.

tsname

The name of a timeseries object within the tscollection .

Examples

Plot Time Series Object with Specified Start Date

Create a time series object, set the start date, and then plot the time vector relative to the start date.

x = [2 5 8 2 11 3 6];
ts1 = timeseries(x,1:7);
ts1.Name = 'Daily Count';
ts1.TimeInfo.Units = 'days';
ts1.TimeInfo.StartDate='01-Jan-2011' % Set start date.
ts1.TimeInfo.Format = 'mmm dd, yy'   % Set format for display on x-axis.
ts1.Time=ts1.Time-ts1.Time(1);       % Express time relative to the start date.
plot(ts1)

Plot Two Time Series Objects on the Same Axes

Create two time series objects from traffic count data, and then plot them in sequence on the same axes. Add an event to one series, which is automatically displayed with a red marker.

load count.dat;
count1=timeseries(count(:,1),1:24);
count1.Name = 'Oak St. Traffic Count';
count1.TimeInfo.Units = 'hours';
plot(count1,':b'), grid on

% Obtain time of maximum value and add it as an event:
[~,index] = max(count1.Data);
max_event = tsdata.event('peak',count1.Time(index));
max_event.Units = 'hours';
% Add the event to the time series:
count1 = addevent(count1,max_event);
% Replace plot with new one showing the event:
plot(count1,'.-b'), grid on

% Make a new ts object from column 2 of the same data source:
count2=timeseries(count(:,2),1:24);
count2.Name = 'Maple St. Traffic Count';
count2.TimeInfo.Units = 'Hours';
% Turn hold on to add the new data to the plot:
hold on
% The plot method does not add labels to a held plot.
% Use property/value pair to customize markers:
plot(count2,'s-m','MarkerSize',6),

% Labels are erased, so generate them manually:
title('Time Series: Oak Street and Maple Street')
xlabel('Hour of day')
ylabel('Vehicle count')
% Add a legend in the upper left:
legend('Oak St.','Maple St.','Location','northwest')

See Also

plot | setinterpmethod | timeseries | tscollection | tsdata.event

  


» Learn more
» Download free kit
» Get trial software

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS