Re: Plot question
- To: mathgroup at smc.vnet.net
- Subject: [mg80864] Re: Plot question
- From: Szabolcs <szhorvat at gmail.com>
- Date: Tue, 4 Sep 2007 06:33:08 -0400 (EDT)
- Organization: University of Bergen
- References: <fbj2c3$nc9$1@smc.vnet.net>
Yaroslav Bulatov wrote: > Why does the plot below make all 3 curves the same color? > > Plot[{a x, 2 a x, 3 a x} /. a -> 2, {x, 1, 2}, > PlotStyle -> {Red, Green, Blue}] This is one of the most common questions on MathGroup. The example you gave doesn't even work in Mathematica 5.2, because "Plot::plnr {a x, 2 a x, 3 a x} /. a -> 2 is not a machine-size real number at x = some value" It is not a number but a list of numbers. But since Plot holds its first argument, and '{a x, 2 a x, 3 a x} /. a -> 2' is a single expression (not a list of expressions), Mathematica expects it to evaluate to a single number (not a list). Probably it wasn't such a good idea to make this example work in Mathematica 6. The incorrect colouring just confuses users, and there is no error message with a hint about what has gone wrong. The solution is to evaluate '{a x, 2 a x, 3 a x} /. a -> 2' before passing it to Plot[] : Plot[{a x, 2 a x, 3 a x} /. a -> 2 // Evaluate, {x, 1, 2}, PlotStyle -> {Red, Green, Blue}] Szabolcs