Re: weird behavior when plotting multiple functions in 6.0
- To: mathgroup at smc.vnet.net
- Subject: [mg76077] Re: weird behavior when plotting multiple functions in 6.0
- From: Szabolcs <szhorvat at gmail.com>
- Date: Wed, 16 May 2007 05:19:40 -0400 (EDT)
- Organization: University of Bergen
- References: <f2btov$iga$1@smc.vnet.net>
Roman wrote: > Hello all: > > When I plot > Plot[{Sin[x], Cos[x]}, {x, 0, 4*Pi}] > I get two curves: one blue, one red. > > But when I do > f[x_] = {Sin[x], Cos[x]}; > Plot[f[x], {x, 0, 4*Pi}] > both curves are blue. It is as if at some level Mathematica does not > understand that I'm actually plotting two curves at a time, and uses > the first color specification (blue) for both curves. > > This is particularly annoying when you want to play with plot styles, > for example filling instructions, like > Filling -> {1 -> -1, 2 -> 1} > which works in the first example but not in the second one. > > Has anyone figured out a workaround for this one? > > Thanks! > Roman. I wouldn't call this behaviour weird. Plot has HoldAll and there is no way of knowing whether f[x] evaluates to a simple expression or a list of two expressions or a list of three expressions etc. ... There isn't even any guarantee that f[x] evaluates to a list of the same length for all x. The surprising thing is that this way of plotting works at all! In version 5.2 Plot looks at its first argument, and sees that it is not a list, but a single expression, so it complains with Plot::plnr when it finds that for numerical arguments f[x] evaluates to a List. Perhaps the old behaviour is less confusing, but with Plot::plnr turned off by default it wouldn't be a good choice.