ListPlot needs a list (duh). Assume that you have a problem where time is not the issue, but space, e.g. compute and plot the first billion values of Fibonacci[n]/GoldenRatio^n. Iteratively you can do it in O(1) time for each step (if you cheat with GoldenRatio - it's just an example). Storing all these values in a list to plot it...just no.

Thus, can you do something like ListPlot with the list being generated on the fly, the plot function just looking at the element currently generated? (Related note, wrong SE: can Python's matlibplot do it? You could put that into comments if you happen to know.)


2 Answers 2


This solution uses the "RingBuffer" data structure.

npts = 16;
xticks = Transpose[{Range[1, npts], ToString /@ Range[-npts, -1]}];


ds = CreateDataStructure["RingBuffer", npts];
Do[ds["PushBack", i], {i, npts}];

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}

ListPlot updates with a Refresh interval of 0.5s:

   , PlotStyle -> {Thick, Red}
   , Ticks -> {xticks, Automatic}
   ], UpdateInterval -> 0.5]

Test: (add 10 values)

 ds["PushBack", RandomInteger[{1, 7}]];
 {i, 1, 10}

Result: (starts with the values from 1-16 initially and then the recently entered points are kept only.

enter image description here

  • 1
    $\begingroup$ You beat me to it. +1 $\endgroup$
    – Edmund
    Commented Feb 27, 2022 at 14:43
  • $\begingroup$ I upped this one as it is immediately clear to me what a ring buffer does. Since both offers use "Dynamic", I give that function a closer look :-) $\endgroup$ Commented Feb 28, 2022 at 9:20

Here is an example using "Dynamic". We simulate the long calculation by "Pause":

x = 1;
tot = Graphics[Point[{x, x^2}]];
next[t_] := (tot = 
     Show[tot, Graphics[Point[{++x, x^2}]], Axes -> True, 
      AspectRatio -> 1];);
Do[next[tot]; Pause[0.5];, {20}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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