Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a long list of {date,value}.

I would like to use DateListPlot to plot only a subrange, from date1 to date2, with the range on the y-axis automatically chosen to be between the min and max value between those two dates (i.e. trivial automatic zooming).

I am sure Mathematic will do it with a simple option choice, but I must be dumb and cannot find it.

Can you help?


PS: here is simple code to show the issue using financial data:

spx = FinancialData["SP500", All];

 PlotRange -> {{{1987, 10, 1}, {1987, 11, 30}}, Automatic}, 
 PlotLegends -> Placed[namesFrom83, {Left, Bottom}], 
 PlotLabel -> "1987"]
share|improve this question
Probably you will be interested in How to manipulate 2D plots. – Kuba Oct 25 '13 at 19:56
It is unclear to me what the problem is. Why not just PlotRange -> {{{1987, 10, 1}, {1987, 11, 30}}, All}? – Mike Honeychurch Oct 26 '13 at 0:04

I rather define my own filter to get new data and put it into DateListPlot:

iDateFilter[data_, st_, end_] :=
 Block[{is, ie},
  is = Position[spx, x_ /; AbsoluteTime[x[[1]]] >= AbsoluteTime[st], {1}, 1, 
     Heads -> False];
  ie = Position[spx, x_ /; AbsoluteTime[end] <= AbsoluteTime[x[[1]]], {1}, 1, 
    Heads -> False];
  Take[data, Flatten[{is, ie}]]

DateListPlot[iDateFilter[spx, {1987, 10, 1}, {1987, 11, 30}], 
 PlotLabel -> "1987"]
share|improve this answer

Using spx as defined:

With[{min = Min[spx[[;; , 2]]], max = Max[spx[[;; , 2]]]},
  PlotRange -> {{{1987, 10, 1}, {1987, 11, 30}}, {0.9 min, 1, 1 max}},
   PlotLabel -> "1987", Joined -> True]]   

(omitting label):

Care may be needed if other datasets have missing values.

enter image description here

share|improve this answer
so you are telling me there is no simple option to tell Mathematica to do it? I am amazed, it is such a basic plotting functionality! – Alberto Oct 26 '13 at 13:28
by the way, from the picture attached it seems that the second solution does not work: it is plotting the whole date range, not those 2 months in 1987 (look at the values on the y axis and you will see it immediately) – Alberto Oct 26 '13 at 13:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.