Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

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


  • Prev by Date: Re: plotting equations with units
  • Next by Date: double integral of long expression in Mathematica
  • Previous by thread: Re: Plot question
  • Next by thread: Re: Plot question