MathGroup Archive 2009

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

Search the Archive

Re: What's going on here (Table-generated lists)?

  • To: mathgroup at
  • Subject: [mg97982] Re: [mg97956] What's going on here (Table-generated lists)?
  • From: Sseziwa Mukasa <mukasa at>
  • Date: Fri, 27 Mar 2009 05:34:26 -0500 (EST)
  • References: <>

On Mar 26, 2009, at 6:24 AM, Erik Max Francis wrote:

> I'm seeing a difference in behavior with Plot in conjunction with  
> Table,
>   and I'm rather confused at the reason.  If I use Plot to plot a list
> of functions, it works as expected, and I get a plot with each  
> function
> in its own color:
> Plot[{x, 2 x, 3 x, 4 x, 5 x}, {x, -1, 1}]
> If I use Table, then this doesn't work the same way -- the five lines
> are all plotted with the same color:
> Plot[Table[k x, {k, 1, 5}], {x, -1, 1}]
> I verified that the both objects created have a Head of List, so I  
> don't
> see anything obviously different about them.
> Here's what confuses me more:  If I generate the table separately and
> then use that as a result in a later evaluation in the Plot, then I  
> get
> the colors back:
> In[25]:= Table[k x, {k, 1, 5}]
> Out[25]= {x, 2 x, 3 x, 4 x, 5 x}
> In[26]:= Plot[%, {x, -1, 1}]
> What is going on here?  Is it something like Plot does a special  
> scan of
> its first argument before Evaluating it, and if it doesn't start  
> out as
> a List, it concludes that it's all one thing and plots it with the  
> same
> color, as opposed to an explicitly provided list of separate colors?

Something like that, some functions evaluate their arguments in a non- 
standard fashion, Plot being one of them.  This is usually mentioned  
in the help on the function.  In particular Plot has the attribute  
HoldAll which means its arguments are not evaluated before Plot is  
evaluated, you can override this with an explicit evaluate:

Plot[Evaluate[Table[k x, {k, 1, 5}]], {x, -1, 1}]

- Ssezi

  • Prev by Date: Interpolation with Method->Spline
  • Next by Date: Re: What's going on here (Table-generated lists)?
  • Previous by thread: What's going on here (Table-generated lists)?
  • Next by thread: Re: What's going on here (Table-generated lists)?