# Monitor - how to stop at last plot

I am using ListPlot to plot some data, the corresponding function is named showListPlot. Now I would like to show a series of such plots in the same window. To do that I am using the following:

Monitor[For[index = 1, index < number + 1, index++,
s = showListPlot[index]] , s]


I would like that monitor stops at the last plot (to see the end state) and does not vanish. How is that possible?

• You might consider whether Animate and ListAnimate are possible alternative approaches. For loops are unnecessary and are included in Mathematica, IMO, to make it easy to translate C/Fortran code. If such a loop is needed in your actual application, consider Do. – Michael E2 Mar 3 '15 at 14:09
• I combined you hint with kgulers code, which is also nice: lp = ListPlot[#, PlotRange -> {{0, 50}, {0, 10}}] & /@ RandomReal[10, {10, 50}]; showlp = Show[lp[[#]], PlotLabel -> Style["index = " <> ToString@#, 16, Bold]] &; number = Length[lp]; ListAnimate[Table[showlp[index], {index, 1, number}], AnimationRepetitions -> 1] – mrz Mar 3 '15 at 14:30

lp = ListPlot[#, PlotRange -> {{0, 50}, {0, 10}}] & /@ RandomReal[10, {10, 50}];
showlp = Show[lp[[#]], PlotLabel -> Style["index = " <> ToString@#, 16, Bold]] &;
number = Length[lp];


Update: If you don't have to use Monitor, there are a number of alternatives including Dynamic and Clock combination:

Dynamic@With[{c = Clock[{1, number, 1}, 5, 1]}, showlp[c]] Original post:

Monitor[For[index = 1, index < number, Pause[.3]; index++, s = showlp[index]], s]; showlp[number] • Thank you kguler. I have the impression that this routine is showing the last plot twice? – mrz Mar 3 '15 at 13:57
• @MilenkoRubin-Zuzic, you are right. If that is an issue, you can change number+1 to number and s at the end to showlp[number]. – kglr Mar 3 '15 at 14:01
• That's it. Why so easy ... can you change the upper code , so that I can vote for the answer? – mrz Mar 3 '15 at 14:14
• @Milenko, just updated the answer. – kglr Mar 3 '15 at 14:19
• Michael E2 had the idea tu use ListAnimate. So we could also could replace the line with Monitor[] ... to: ListAnimate[Table[showlp[index], {index, 1, number}], AnimationRepetitions -> 1]. Also nice ... – mrz Mar 3 '15 at 14:32
showListPlot[index_] := {Plot[x, {x, 0, 3}], Plot[x^2, {x, 0, 3}], Plot[x^3, {x, 0, 3}]}[[index]]

number = 3;

Block[{printFunction = PrintTemporary},
Do[If[index == number, printFunction = Print];
printFunction[showListPlot[index]]; Pause
, {index, number}]
]


Monitor is still better I guess, but here it goes the edit:

showListPlot[index_] := {Plot[x, {x, 0, 3}], Plot[x^2, {x, 0, 3}], Plot[x^3, {x, 0, 3}]}[[index]]

number = 3;

PrintAndDelete[expression_]:=Module[{cell},cell=PrintTemporary[expression];Pause;NotebookDelete[cell]]

Module[{printFunction=PrintAndDelete},
Do[If[index==number,printFunction=Print];printFunction[showListPlot[index]],{index, number}]
]

• Dear Giovanni, I would like to see the curves in the "same window cell" and that the last plot is not cleared. – mrz Mar 3 '15 at 14:10
• Dear Giovanni, interesting ... I did not know this ... thanks – mrz Mar 3 '15 at 14:44