Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #1521

Re: Bug with map in conjuntion with plotstyle?

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Bug with map in conjuntion with plotstyle?
Date 2011-04-07 12:06 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ink9bj$gan$1@smc.vnet.net> (permalink)

Show all headers | View raw


On 4/6/11 at 5:11 AM, jason.lee.quinn@gmail.com (Jason Quinn) wrote:

>values = {0.5, 1.0, 2.0};

>f[x_, y_] := x^2 + y

>Plot[{f[x, #]} & /@ values, {x, 0, 6}, PlotStyle -> {{Red}, {Blue},
>{Yellow}}]

>thing = {f[x, #]} & /@ values

>Plot[thing, {x, 0, 6}, PlotStyle -> {{Red}, {Blue}, {Yellow}}]

>I'm trying to use map to generate a list of functions to plot and
>use PlotStyle to define the color and style of the plot.
>Unfortunately, it seems like there's a bug here. When map is used
>with Plot, it applies the first plotstyle to all the plots.

>I think the above is a good test case. The first plot only plots
>red. The second plot plots red, blue, and green as desired.

>Am I misunderstanding something about plot, map, or plot style? Or
>is this a bug?

This isn't a bug. Instead, it is a direct consequence of how
Plot evaluates its arguments. With

Plot[f[x, #]} & /@ values, ...

Plot first substitutes a numerical value for x then evaluates
f[x, #]&/@values. That is when the evaluation of the argument is
complete, Plot sees a list of numerical values which is exactly
what you would get if you were to plot a single multi-value
function and only one color is used in the plot.

When you first do thing = f[x, #]&/@values then do
Plot[thing...]. Plot sees something that has head List and sees
it as a list of functions to be plotted. Consequently, each is
colored according to your PlotStyle directive.

Doing

Plot[Evaluate[f[x,#]&/@values] ...

forces evaluation of f[x,#]&/@values before Plot does anything.
So, this will result in separate colors.

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Bug with map in conjuntion with plotstyle? Bill Rowe <readnews@sbcglobal.net> - 2011-04-07 12:06 +0000

csiph-web