MathGroup Archive 2011

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

Search the Archive

Re: and color via PlotStyle

  • To: mathgroup at smc.vnet.net
  • Subject: [mg118484] Re: and color via PlotStyle
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 29 Apr 2011 07:33:49 -0400 (EDT)

On 4/28/11 at 6:34 AM, cy56 at comcast.net (Christopher O. Young) wrote:

>As a previous poster showed, Plot is a little inconsistent when it
>comes to mapping colors via PlotStyle.

>Plot[
>{ a x /. {a -> 1}, a x^2 /. {a -> 1}, a x^3 /. {a -> 1}
>},{x, 0, 2},PlotStyle -> {Red, Green, Blue}]

>works OK but

This works as you are expecting only because the argument to
Plot is an explicit list. This is the only case where Plot uses
multiple colors.

>Plot[{ a x, a x^2, a x^3}/. {a -> 1},{x, 0, 2},
>PlotStyle -> {Red, Green, Blue}]

>just produces blue plots.

Exactly as it should. Plot always evaluates its arguments by
first substituting a numeric value for the independent variable
and only after that is the expression evaluated. The consequence
it for the argument above, Plot does not see a list of
expressions. Instead it sees a list of numeric values which is
treated as a single function with multiple values and
consequently plotted in a single color.

You can force evaluation of the expression before a numeric
value is substituted for the plot variable by using Evaluate.
That is doing

Plot[Evaluate[{ a x, a x^2, a x^3}/. {a -> 1}],{x, 0, 2}]

will result in Plot seeing an explicit list of expressions which
will get plotted in different colors.

There is no inconsistency in the behavior of Plot. The behavior
I am describing is well documented even if not always well understood.



  • Prev by Date: Re: Expected value of the Geometric distribution
  • Next by Date: Re: Expected value of the Geometric distribution
  • Previous by thread: Re: for cicle inside an If condition
  • Next by thread: Re: and color via PlotStyle