[Date Index]
[Thread Index]
[Author Index]
Re: Plot Table of functions does not distinguish colors
*To*: mathgroup at smc.vnet.net
*Subject*: [mg102689] Re: Plot Table of functions does not distinguish colors
*From*: Bill Rowe <readnews at sbcglobal.net>
*Date*: Wed, 19 Aug 2009 07:01:25 -0400 (EDT)
On 8/18/09 at 6:09 AM, fdimer at gmail.com (fd) wrote:
>All, this seems like a simple question, but when I want to create a
>table with different function as in the example
>Plot[Table[Sin[n x], {n, 1, 3, 1}], {x, 0, 2 Pi}, PlotRange -> All,
>PlotStyle -> Thick]
>I get all three plots with the same color. If I instead write the
>table manually
>Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, 0, 2 Pi},PlotStyle->Thick]
>This gives a different plot with a different color for each plot.
>Can anyone shed some light on why this behavior?
This is due to the way in which Plot evaluates its arguments. It
substitutes a numerical value for the dependent variable into
the expression to be plotted then evaluates the expression. When
you give Plot an expression that evaluates to a list of values,
Plot sees this as a single multi-valued function and plots it in
one color. If you give Plot an explicit list, Plot sees that
list as several functions and plots each in a separate color.
So, to get an expression that generates a list of values to plot
in several colors, you need to force evaluation of the
expression before Plot starts doing its thing, You can do this
with Evaluate.
That is:
Plot[Evaluate@Table[Sin[n x], {n, 1, 3, 1}], {x, 0, 2 Pi},
PlotRange -> All,
PlotStyle -> Thick]
will result in a Plot with each curve plotted in a separate color.
Prev by Date:
**Inconsistency in ListPlot vs. other plotting functions (solution)**
Next by Date:
**Re: Plot: Problem with Mesh Option**
Previous by thread:
**Re: Plot Table of functions does not distinguish colors**
Next by thread:
**Re: Plot Table of functions does not distinguish colors**
| |