MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ListLinePlot[] inside a loop


Luiz Melo wrote:
> Hi mathgroup,
> 
> Why is the plot of a list not displayed when ListLinePlot[] is used inside a Do
> loop (Mathematica 6.0)?
> For instance, suppose we want to produce the graphics of Sin[i*x] as a function
> of x, each time i is iterated from 1 to 3 (in steps of 1). I naively tryed:
> 
> Do[ListLinePlot[Table[{x, Sin[i*x Degree]}, {x, 0, 360}],
>    PlotRange -> {{0, 360}, {-1.1, 1.1}}], {i, 1, 3}];

In Mathematica 6, graphics are like any other value.  Instead of being 
drawn as a side effect, they are simply /returned/ by plotting 
functions.  Do[] always returns Null, so replace it with Table and 
remove the ; from the end.  You might want to wrap the output in Column[] :

Table[ListLinePlot[Table[{x, Sin[i*x Degree]}, {x, 0, 360}],
    PlotRange -> {{0, 360}, {-1.1, 1.1}}], {i, 1, 3}] // Column

> The specifications "For[]" and "While[]" don't work either.

While[] and For[] are better avoided in Mathematica.  If you really 
insist on using such functions, then try

Do[Print@ListLinePlot[Table[{x, Sin[i*x Degree]}, {x, 0, 360}],
    PlotRange -> {{0, 360}, {-1.1, 1.1}}], {i, 1, 3}]

-- 
Szabolcs


  • Prev by Date: Re: Finds strings in a list that begin with "A"
  • Next by Date: Re: ListLinePlot[] inside a loop
  • Previous by thread: Re: ListLinePlot[] inside a loop
  • Next by thread: Re: ListLinePlot[] inside a loop