Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a function, which plots the given function array f. This is a part of the function:

Plot[-f, {x,0,2}, Filling->{1->{2}}, PlotStyle->Green]

When I specify {x^2, 2x} as the function f, I get the errors "2 must be an integer between 1 and 1. " and "{2} is not a valid Filling specification.". I get this error because I have a minus sign in front of the argument f. If I plot {-x^2,-2x} then everything is fine. So how to multiply everything in f by -1 without getting these errors?

share|improve this question
up vote 7 down vote accepted

You need to evaluate the first argument of Plot before sampling the specific datapoints, as the multiplication (the minus sign before the list of functions) does not get thread over the list by default, as Plot has attribute HoldAll. This means that your example Plot is practically called with only one function (which is a List) and therefore the Filling specification does not make sense. Discussed in more detail here.

Plot[Evaluate[-{x^2, 2 x}], {x, 0, 2}, Filling -> {1 -> {2}}, PlotStyle -> Green]

This effectively equals the following (note that the - signs are in front of the individual functions):

Plot[{-x^2, -2 x}, {x, 0, 2}, Filling -> {1 -> {2}}, PlotStyle -> Green]

Both produce the following correct plot:

Mathematica graphics

share|improve this answer

As István Zachar describes this is an evaluation problem. I recommend however using a different form:

Plot[-f, {x, 0, 2}, Filling -> {1 -> {2}}, PlotStyle -> Green, Evaluated -> True]

This is superior to Evaluate[-f] in that the Plot variable (x) is correctly localized.

For example:

f := {x^2, 2 x};

x = 7; (* accidental definition *)

Plot[-f, {x, 0, 2}, Filling -> {1 -> {2}}, PlotStyle -> Green, Evaluated -> True]

Mathematica graphics

The other method fails:

Plot[Evaluate[-f], {x, 0, 2}, Filling -> {1 -> {2}}, PlotStyle -> Green]

Mathematica graphics

share|improve this answer
+1 for the foolproof method. Am I right in assuming that this is an undocumented option (I never heard of before)? – István Zachar May 28 '12 at 9:28
@István as far as I know it is undocumented, but it has been around for a while. – Mr.Wizard May 28 '12 at 9:46
We really need a comprehensive list of undocumented symbols and string options. I'm not sure adding Evaluated to this huge and messy list would help anyone... – István Zachar May 28 '12 at 10:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.