File Exchange

image thumbnail

Shaded time series

version 1.5 (2.88 KB) by

Plot time series one above the other with coloured strips highlighting interesting features.

8 Downloads

Updated

View License

Use this function to plot several time series aligned beneath each other with shaded blocks highlighting important sections.

Comments and Ratings (7)

Carl Fischer

Hi Joe,

It sounds like you want multiple lines on a single plot instead of several subplots. There are many variations like this and I don't know how to deal with them without adding loads of parameters or creating several new functions.

I think you can work around it as follows. Run shadedTimeSeries(x,y1,indicator) first. This will give you a single plot with the coloured bars. Then 'hold all'. Then plot(x,y2); plot(x,y3)... This will overlay your other plots on top. Unfortunately, the height of the bars is based on the values of y1, so you have to make sure that y1 goes above and below the other variables.

Feel free to tweak the script for your own purposes. I think you just need to call the internal plot_partial() function with multiple columns in ydata.

-- Carl

Joerg Vetter

Hi Carl,
thanks a lot for this script and the examples. It's totally what I needed.

But how could I manage to put shade in a plot which contains several different lines of data.

Example: One contains the data:
plot(vec1);
hold on;
plot(vec_2);
-->now I'd like to use your shadedTimeSeries function within this single plot

Is this possible?
cheers Joe

Carl Fischer

I uploaded a new version which allows you run this function with only one column of data to populate your own subplots (instead of creating a new figure). Not sure if that's what Kuo-Hsien was requesting. See the examples in the documentation to see how this works.

Carl Fischer

Thanks for the feedback. Not sure what you mean about subplots.
If you just want to display the part of the legend that shows the shaded colour then you can add legend('Interesting bit'); after this function. I feel that anything more sophisticated will be difficult to generalise and may be quite specific to your particular problem. It might be easier if you tweak the function yourself.

Kuo-Hsien

Hi Carl, this is a useful function. How to show the box for subplots and legend? thx.

Carl Fischer

Thanks for the suggestion Shlomi. I've submitted an update but I also added some extra sanity checks to ensure sizes are consistent.

shlomix

if the indicator is a row vector the function doesn't work properly. I added the simple command of indicator = indicator(:); in my code. You should add it too

Updates

1.5

Slight improvement to parameter consistency checks.

1.4

Accept different indicators to shade each subplot differently.
If the user specifies a single column of data then use the current plot instead of creating a new one to allow the user more control (eg. custom subplots).

1.3

Detect inconsistent data lengths.

1.2

Fixed bug that occurred when X was a row vector.

1.1

Allow data in rows or columns. Extra sanity checks on data lengths.

MATLAB Release
MATLAB 7.10 (R2010a)
Acknowledgements

Inspired by: ShadePlotForEmphasis

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video