1
$\begingroup$

I´m trying to obtain ListPlot inside a DO loop but, always I can see the final semicolon in red, and the code runs well except the PLOTS.

How can I obtain the ListPlots in each iteration?

a = {};
Do[
 sa = {{RandomInteger[9] + 1, 
    RandomInteger[9] + 1}, {RandomInteger[9] + 1, 
    RandomInteger[9] + 1}, {RandomInteger[9] + 1, 
    RandomInteger[9] + 1}};
 AppendTo[a, sa];
 Print["sa-> ", sa, " and a = ", a];
 ListPlot[a, PlotRange -> {{0, 10}, {0, 10}}];
 ListPlot[sa, PlotRange -> {{0, 10}, {0, 10}}];
 Print["iter= ", i]
 , {i, 1, 3}
 ]

After reading some of the posts in the first link of DUPLICATE, I modify with this code(in an easy way), but I think that the solutions are not suitable when in each iteration you want to write many data and the Plot is only ONE (but not the main purpose). You can supose you want to print 15 lineas of data and a plot in each iteration, similar to , as the sketch after the next code. If you obtain all the plots at the final in a Table is not so useful. (I think that Mathematica is so complicated for any simple things.)

a = {};
plota = {};
plotsa = {};
Do[
 sa = {{RandomInteger[9] + 1, 
    RandomInteger[9] + 1}, {RandomInteger[9] + 1, 
    RandomInteger[9] + 1}, {RandomInteger[9] + 1, 
    RandomInteger[9] + 1}};
 costesa = coste[sa];
 AppendTo[a, sa];
 Print["sa-> ", sa, " and a = ", a];
 (*sp=ListPlot[a,PlotRange\[Rule]{{0,10},{0,10}}];*)
 AppendTo[plota, ListPlot[a, PlotRange -> {{0, 10}, {0, 10}}]];
 AppendTo[plotsa, ListPlot[sa, PlotRange -> {{0, 10}, {0, 10}}]];
 Print["iter= ", i]
 , {i, 1, 3}
 ]
plota
plotsa

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Just use Print. $\endgroup$ – Sjoerd C. de Vries Feb 16 '15 at 20:28
  • $\begingroup$ @SjoerdC.deVries :-) Yes!. Just.... Thank you very much. You have really solve my question. QUESTION SOLVED! $\endgroup$ – Mika Ike Feb 16 '15 at 21:21
1
$\begingroup$

Here is an alternative approach (apologies if I have misinterpreted the desired output)

With[{pr = Table[{0, 10}, {2}]}, 
 Column[#, Frame -> All] & /@ Transpose[{MapIndexed[
       Column[{ListPlot[#1, 
           PlotLabel -> "Iteration" <> ToString@First@#2, 
           PlotRange -> pr, Frame -> True], #1}]
        &, #], 
      Column[{ListPlot[#, PlotRange -> pr, Frame -> True], #}] & /@ 
       FoldList[Join[#1, #2] &, First@#, Rest@#]} &@
    RandomInteger[{1, 10}, {3, 3, 2}]]]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you. But what I want is printing a ListPlot in each iteration inside a Do[] and other data. The List Plot is only one of the data I want. $\endgroup$ – Mika Ike Feb 16 '15 at 18:23

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