Message Boards Message Boards

1
|
6387 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Time Series Plot in Staircase Format

Posted 10 years ago

I am trying to generate a staircase plot in the format shown in the bottom right image below from the time series data in the enclosed example file. Is there an efficient way to generate the staircase plot? Ideally I need to add a "sample & hold" feature to each data point which could be created either by duplicating time series entries or by using a unique shape with the desired width for each time series point?

thanks

enter image description here

Attachments:
POSTED BY: Bob Stephens
4 Replies
Posted 10 years ago

Agree - the Manipulate functionality is well designed and it probably makes sense to just use Manipulate features which are more flexible than a hard-wired option in ListLinePlot. Thanks for the suggestion - see final result below.

enter image description here

POSTED BY: Bob Stephens

I'd guess that WRI would not add such an option since it is avery specific analysis situation rather than more general. But one could certainly write a small bit of code that implements a case like this--I'm sure. It'd most easily be done using a Dynamic approach using the PlotRange option.

Here is a quick and very incomplete sketch:

randomData = Table[Sin[i/100] + i/1000 Random[], {i, 0, 10000}]; 

Manipulate[
 ListPlot[randomData, PlotRange -> {{x, x + window}, {-4, 4}}, 
  Frame -> True],
 {x, 0, 1000},
 {window, 100, 1000}
 ] 
POSTED BY: David Reiss
Posted 10 years ago

Thanks David that does indeed work, I should have looked at a smaller data set first. A good option for ListLinePlot would be a setting that allows the user to set a "window size" on a long list and add a scroll view to the plot so that in this case you would see the entire data set (with this option set) but only if you move the horizontal scroll bar. You could generate the same thing in manipulate but it would be nice if ListLinePlot could simply add it as an option.

POSTED BY: Bob Stephens

If one reads in your file as follows and call the result data

data = Flatten@Import["path to timeSeriesData.csv"]

then you will get a staircase plot using ListLinePlot if you set its InterpolationOrder option to 0 as in:

ListLinePlot[data[[;; 100]], InterpolationOrder -> 0]

I am only plotting the first 100 points from data here since plotting the full 1000 points just results in a dense plot that shows as a single block of color for your particular data set.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract