# How to change start and end date of DateListPlot with Manipulate?

Let's say I have a one dimension list d with length L. The $x$-axis in the plot starts from {2013, 8, 28 + start} and ends in {2013, 8, 28 + end}, and I want to change the start and end date with Manipulate.

So

d[] (*--> 2013/8/28*)

d[] (*--> 2013/8/29*)


So I think it would be:

Manipulate[
DateListPlot[d, {{2013, 8, 28 + start}, {2013, 8, 28 + end}}],
{{start, 0}, 0, L},
{{end, L}, 0, L}
]


But when I plot it, it gives me an error when a>3 because the day of the date is greater than 31 (I think).

How would be the correct way to do this?

L = 20;
Manipulate[
DateListPlot[Range@50, {DatePlus[{2013, 8, 28}, start], DatePlus[{2013, 8, 28}, end]}],
{{start, 0}, 0, L},
Item[Dynamic@DatePlus[{2013, 8, 28}, start], Alignment -> Left],
{{end, L}, 0, L},
Item[Dynamic@DatePlus[{2013, 8, 28}, end], Alignment -> Left]] If you do not know the frequency of your data, or just want to be robust to it, there are two options. One is the standard Take or Part constructs. The other is PlotRange, which works fine for the horizontal axis of DateListPlots.

fakedata =
Transpose@{DatePlus[{2001, 1}, {#, "Month"}] & /@ Range[0, 99],
Accumulate[RandomVariate[NormalDistribution[0, 1], {100}]] - 2};

Manipulate[
DateListPlot[fakedata, Joined -> True,
PlotRange -> {{start, end}, Automatic}],
{start, AbsoluteTime@{2000, 12}, AbsoluteTime@{2004, 6}},
{end, AbsoluteTime@{2005, 6}, AbsoluteTime@{2009}}] You could change the outer bounds of the Manipulate ranges for start and end to reference the data if you wanted. Just be careful to make sure that start cannot be greater than end, or Weird Stuff™ happens.

• +1 I wonder whether the logo of **Weird Stuff**™ is a pentagon or an heptagon Nov 20, 2013 at 12:09
• @belisarius it changes randomly between the two, and nobody can understand why. It's weird. ;-) Nov 20, 2013 at 12:12