# “Not a valid Filling specification” error

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?

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: 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] The other method fails:

Plot[Evaluate[-f], {x, 0, 2}, Filling -> {1 -> {2}}, PlotStyle -> Green] • +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