Skip to main content
4 of 4
added 5 characters in body
kglr
  • 403.4k
  • 18
  • 501
  • 959

How to not include data value outside plot range in the plot

Consider this list plot

ls = Table[Sin[t], {t, 0, 100, 0.1}]; p = ListPlot[ls, PlotRange -> {{0., 0.1}, All}, DataRange -> {0, 1}, Joined -> True] 

enter image description here

If we look at the data in the plot, we see that all the data in ls are included in the plot.

ls2 = p[[1, 2, 1, 3, 3, 1]]; Dimensions[ls2] (* {1001, 2} *) ListPlot[ls2, Joined -> True] 

enter image description here

Sometimes this is really helpful because we can just retrieve the data at a later time from the plots and don't need to regenerate the data again. But sometimes I'm only interested in the range set in the ListPlot, and saving all the data is kindly of wasting of space, especially when I have many plots in a notebook, the notebook size becomes very large and not very responsive.

So are there simple ways to tell ListPlot to not include the data outside the plot range, other than manually select the data before plot?

P.S. Sometimes, ListPlot does drop the data outside the range, see example here.

xslittlegrass
  • 28k
  • 9
  • 105
  • 190