Thread Subject: Plotting "breaks" in a single time-series

Subject: Plotting "breaks" in a single time-series

From: mprocopio@gmail.com

Date: 3 Dec, 2008 22:10:26

Message: 1 of 4

Hi all,

I have a single time-series data vector, that I am visualizing with
MATLAB's plot command. The actual plot is somewhat elaborate, but am
using this simple case to isolate the problem.

Essentially, the domain (X-axis values) of the time series is
*repeating*. You could consider it to be, for example, seasonal data.
So I have 5 years of 4 seasons each, totaling 20 data points.

What I'd like to do is to show the plot, then, CONNECTED between
Winter, Spring, Summer, and Fall, with a standard line. Great.

What I do NOT want is the "Fall" data point--the fourth element in the
repeating X-axis "group"--to connect back up to the next element (in
this case, the fifth element, "Winter", which would be the second
occurrence in the 4-element repeating group).

I currently have the plot saved as a *.FIG file, but am not able to
conveniently regenerate it programmatically.

How can I modify the plot to prevent the last element in a given
repeating X-axis group from connecting to the first element of the
next group?

Your help is greatly appreciated.


Very best regards,

Mike

Subject: Plotting "breaks" in a single time-series

From: Johan Carlson

Date: 5 Dec, 2008 07:26:05

Message: 2 of 4

mprocopio@gmail.com wrote in message <78592898-1ba6-4f23-96a7-bfad576db417@z28g2000prd.googlegroups.com>...
> Hi all,
>
> I have a single time-series data vector, that I am visualizing with
> MATLAB's plot command. The actual plot is somewhat elaborate, but am
> using this simple case to isolate the problem.
>
> Essentially, the domain (X-axis values) of the time series is
> *repeating*. You could consider it to be, for example, seasonal data.
> So I have 5 years of 4 seasons each, totaling 20 data points.
>
> What I'd like to do is to show the plot, then, CONNECTED between
> Winter, Spring, Summer, and Fall, with a standard line. Great.
>
> What I do NOT want is the "Fall" data point--the fourth element in the
> repeating X-axis "group"--to connect back up to the next element (in
> this case, the fifth element, "Winter", which would be the second
> occurrence in the 4-element repeating group).
>
> I currently have the plot saved as a *.FIG file, but am not able to
> conveniently regenerate it programmatically.
>
> How can I modify the plot to prevent the last element in a given
> repeating X-axis group from connecting to the first element of the
> next group?
>
> Your help is greatly appreciated.
>
>
> Very best regards,
>
> Mike


I think you can solve this by generating five separate X vectors (one for each year), and then 5 separate Y vectors, which each are all zeros (or possibly NaN) except for the interval where you have data.

/JC

Subject: Plotting "breaks" in a single time-series

From: Steven Lord

Date: 5 Dec, 2008 14:34:54

Message: 3 of 4


<mprocopio@gmail.com> wrote in message
news:78592898-1ba6-4f23-96a7-bfad576db417@z28g2000prd.googlegroups.com...
> Hi all,
>
> I have a single time-series data vector, that I am visualizing with
> MATLAB's plot command. The actual plot is somewhat elaborate, but am
> using this simple case to isolate the problem.
>
> Essentially, the domain (X-axis values) of the time series is
> *repeating*. You could consider it to be, for example, seasonal data.
> So I have 5 years of 4 seasons each, totaling 20 data points.
>
> What I'd like to do is to show the plot, then, CONNECTED between
> Winter, Spring, Summer, and Fall, with a standard line. Great.
>
> What I do NOT want is the "Fall" data point--the fourth element in the
> repeating X-axis "group"--to connect back up to the next element (in
> this case, the fifth element, "Winter", which would be the second
> occurrence in the 4-element repeating group).
>
> I currently have the plot saved as a *.FIG file, but am not able to
> conveniently regenerate it programmatically.
>
> How can I modify the plot to prevent the last element in a given
> repeating X-axis group from connecting to the first element of the
> next group?

Hint:

x = [1:4 NaN 1:4];
y = [1:4 NaN 5:8];
plot(x, y)

GET the data from the lines in the figure, tweak the data to use this
technique, then SET the appropriate line properties using the updated data.

--
Steve Lord
slord@mathworks.com

Subject: Plotting "breaks" in a single time-series

From: mprocopio@gmail.com

Date: 5 Dec, 2008 22:54:26

Message: 4 of 4

Johan, Steve:

I sincerely thank you both for your excellent and timely advice. I am
extremely happy to report that using your method, I was successfully
able to achieve the desired behavior, and the resulting plot looks
phenomenal, and with a higher "data to ink" ratio (Edward Tufte would
be proud). I needed and appreciate both the NaN idea as well as
Steven's specific hints.

This was a one-off plot, so here's the code I prototyped. This can be
easily be improved at a later date (i.e., smarter insert
functionality).

Thank you again!

--Mike


function modify_figure

gca_children = get(gca, 'Children');

xdata = (get(gca_children(1), 'xdata'));
xdata2 = zeros(1, size(xdata, 2) + 5);
xdata2(:) = NaN;

xdata2(1:4) = xdata(1:4);
xdata2(6:9) = xdata(5:8);
xdata2(11:14) = xdata(9:12);
xdata2(16:19) = xdata(13:16);
xdata2(21:24) = xdata(17:20);
xdata2(26:29) = xdata(21:end);

ydata = (get(gca_children(1), 'ydata'));
ydata2 = zeros(1, size(ydata, 2) + 5);
ydata2(:) = NaN;

ydata2(1:4) = ydata(1:4);
ydata2(6:9) = ydata(5:8);
ydata2(11:14) = ydata(9:12);
ydata2(16:19) = ydata(13:16);
ydata2(21:24) = ydata(17:20);
ydata2(26:29) = ydata(21:end);

set(gca_children(1), 'xdata', xdata2);
set(gca_children(1), 'ydata', ydata2);

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com