Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Extracting the points from a line in a ListPlot in this answer uses

points = Cases[Normal@plot, Line[pts_] :> pts, Infinity];

This works in DateListPlot (provided Joined->True) (example below, using Last to get the y-axis data only)


enter image description here


However, when the plot is limited by PlotRange using date values (lower plot), the function returns the entire list of points.


enter image description here


Is there a function, like points which can return only the points displayed on the plot in DateListPlot under 'PlotRange` ?

share|improve this question
You can just use Select on the result with conditions similar to those in PlotRange. –  Kuba Jun 9 '14 at 23:27
Related –  rasher Jun 9 '14 at 23:33
@Kuba Appreciated. Pickett is along those lines too and delves into the plot function to retrieve the bounds –  PlaysDice Jun 9 '14 at 23:41
@rasher Thanks. The linked answer is a serious Module indeed! –  PlaysDice Jun 9 '14 at 23:51

1 Answer 1

up vote 2 down vote accepted

This should do it:

points2 = 
 With[{range = Part[PlotRange /. Options[plot2], 1]}, 
  Select[Flatten[Cases[Normal@plot2, Line[pts_] :> pts, Infinity], 1],
     First@range <= First@# && First@# <= Last@range &][[All, 2]]]

With plot2 as in your example:

{3., 4., 5.}

share|improve this answer
Yes! I was hoping someone could retrieve the values with Options magic. –  PlaysDice Jun 9 '14 at 23:40
I worked through what you did. Using the Options to make a set of replace rules and PlotRange as the "target of those replace rules" is very neat. I learned something new (again). –  PlaysDice Jun 10 '14 at 2:20
@PlaysDice I'm glad you liked it! :) –  Pickett Jun 10 '14 at 2:27

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.