MathGroup Archive 2011

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

Search the Archive

Re: Coloring curves: not as simple as it sounds..

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118167] Re: Coloring curves: not as simple as it sounds..
  • From: Peter Pein <petsie at dordos.net>
  • Date: Fri, 15 Apr 2011 03:55:37 -0400 (EDT)
  • References: <io6d17$dpl$1@smc.vnet.net>

Am 14.04.2011 10:59, schrieb Jean-Michel Di Nicola:
> All,
>
> I have a question that looks fairly trivial, but I cannot solve it....
> Please help!
>
> Thanks, JM
>
> Here is a simplified toy example.
> When I type
> Plot[{a x /. {a ->  1}, a x^2 /. {a ->  1}, a x^3 /. {a ->  1}}, {x, 0,
>    2}, PlotStyle ->  {Red, Green, Blue}]
> I get 3 curves with different colors.
>
> Well, when I type
> Plot[{a x, a x^2, a x^3} /. {a ->  1}, {x, 0, 2},
>   PlotStyle ->  {Red, Green, Blue}]
> I get 3 curves but they are all blue, WHY?
>
> However, when I evaluate {a x /. {a ->  1}, a x^2 /. {a ->  1}, a x^3 /.
> {a ->  1} and {a x, a x^2, a x^3} /. {a ->  1}, they both give the same
> result....{x, x^2, x^3}.
>
> Thank you for your help!!!
>
Just to go a little more into detail:
Plot has the Attribute HoldAll:

In[3]:= Attributes@Plot
Out[3]= {HoldAll, Protected}

this means that the arguments are not evaluated before plotting really 
starts.
Plot "sees" only one top-level call to ReplaceAll and guesses you've 
given one single-valued function:

In[4]:= FullForm@HoldForm[{a x,a x^2,a x^3}/.{a->1}]
Out[4]//FullForm= 
HoldForm[ReplaceAll[List[Times[a,x],Times[a,Power[x,2]],Times[a,Power[x,3]]],List[Rule[a,1]]]]

in your first example, you give plot a list with 3 ReplaceAlls and Plot 
"knows" that it has to expect three values.

I hope my bad english did not obfuscate the object,
Peter

-- 
my taylor is rich but my english is poor ;-)


  • Prev by Date: Re: Coloring curves: not as simple as it sounds..
  • Next by Date: Re: Undesired horizontal line in Plot / Bug?
  • Previous by thread: Re: Coloring curves: not as simple as it sounds..
  • Next by thread: Undesired horizontal line in Plot / Bug?