Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Extracting the points from a line in a ListPlot in this answeranswer 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)

Clear[test,plot,points]; test={{"2010",1},{"2011",2},{"2012",3},{"2014",4},{"2015",5},{"2016",6}}; plot=DateListPlot[test,Joined->True] points=Last/@Flatten[Cases[Normal@plot,Line[pts_]:>pts,Infinity],1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

plot2=DateListPlot[test,Joined->True,PlotRange->{{"2012","2015"},{0,6}}] points2=Last/@Flatten[Cases[Normal@plot2,Line[pts_]:>pts,Infinity],1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

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)

Clear[test,plot,points]; test={{"2010",1},{"2011",2},{"2012",3},{"2014",4},{"2015",5},{"2016",6}}; plot=DateListPlot[test,Joined->True] points=Last/@Flatten[Cases[Normal@plot,Line[pts_]:>pts,Infinity],1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

plot2=DateListPlot[test,Joined->True,PlotRange->{{"2012","2015"},{0,6}}] points2=Last/@Flatten[Cases[Normal@plot2,Line[pts_]:>pts,Infinity],1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

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)

Clear[test,plot,points]; test={{"2010",1},{"2011",2},{"2012",3},{"2014",4},{"2015",5},{"2016",6}}; plot=DateListPlot[test,Joined->True] points=Last/@Flatten[Cases[Normal@plot,Line[pts_]:>pts,Infinity],1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

plot2=DateListPlot[test,Joined->True,PlotRange->{{"2012","2015"},{0,6}}] points2=Last/@Flatten[Cases[Normal@plot2,Line[pts_]:>pts,Infinity],1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

edited tags
Link
Mr.Wizard
  • 275.2k
  • 34
  • 606
  • 1.5k
Last
Source Link
PlaysDice
  • 814
  • 6
  • 13

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 Flatten and PartLast to get the y-axis data only)

Clear[test,plot,points]; test={{"2010",1},{"2011",2},{"2012",3},{"2014",4},{"2015",5},{"2016",6}}; plot=DateListPlot[test,Joined->True] points=Flatten[Cases[Normal@plotpoints=Last/@Flatten[Cases[Normal@plot,Line[pts_]:>pts,Infinity],1][[All,2]]1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

plot2=DateListPlot[test,Joined->True,PlotRange->{{"2012","2015"},{0,6}}] points2=Flatten[Cases[Normal@plot2points2=Last/@Flatten[Cases[Normal@plot2,Line[pts_]:>pts,Infinity],1][[All,2]]1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

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 Flatten and Part to get the y-axis data only)

Clear[test,plot,points]; test={{"2010",1},{"2011",2},{"2012",3},{"2014",4},{"2015",5},{"2016",6}}; plot=DateListPlot[test,Joined->True] points=Flatten[Cases[Normal@plot,Line[pts_]:>pts,Infinity],1][[All,2]] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

plot2=DateListPlot[test,Joined->True,PlotRange->{{"2012","2015"},{0,6}}] points2=Flatten[Cases[Normal@plot2,Line[pts_]:>pts,Infinity],1][[All,2]] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

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)

Clear[test,plot,points]; test={{"2010",1},{"2011",2},{"2012",3},{"2014",4},{"2015",5},{"2016",6}}; plot=DateListPlot[test,Joined->True] points=Last/@Flatten[Cases[Normal@plot,Line[pts_]:>pts,Infinity],1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

plot2=DateListPlot[test,Joined->True,PlotRange->{{"2012","2015"},{0,6}}] points2=Last/@Flatten[Cases[Normal@plot2,Line[pts_]:>pts,Infinity],1] 

enter image description here

(*OUTPUT {1.,2.,3.,4.,5.,6.} 

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

Source Link
PlaysDice
  • 814
  • 6
  • 13
Loading