Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This example comes from the Mathematica documentation for Plot under Basic Examples.

Can someone please explain why these are each plotted as a different color in this case:

Plot[Evaluate[Table[BesselJ[n, x], {n, 4}]], {x, 0, 10}, Filling -> Axis]

enter image description here

But when Evaluate[] is removed, all of them are the same color:

Plot[Table[BesselJ[n, x], {n, 4}], {x, 0, 10}, Filling -> Axis]

enter image description here

I know it must have to do with the order of things being evaluated, but I'm really not sure why it is working like this - can someone please point me in the correct direction?

share|improve this question
Hmm... I'm almost positive I've seen this question asked here before, but I can't seem to find it... –  David Z Feb 14 '12 at 7:26
Yeah, this is very much an FAQ. –  J. M. Feb 14 '12 at 7:55

4 Answers 4

up vote 42 down vote accepted

The list structure is not manifest to Plot as it has the attribute HoldAll (to get a function's attributes, either use Attributes[func] or ??func). Hence Plot evaluates the Table functions as one unit and it appears as if there is only one function, not four.

Evaluate will make the list structure manifest and each function will be plotted with a separate style.

share|improve this answer
I apologize if this is naive question, but what does "The list structure is not manifest to Plot" mean? –  brown.2179 Dec 30 '13 at 12:23
It means that Plot isn't seeing the argument as a list. A list is treated as one argument not many arguments as Plot has HoldAll attribute . –  Matariki Dec 31 '13 at 22:06

Mathematica 10 update

It seems that now Plot specifically recognizes Sequence which invalidates the example given below, but not its premise. If one uses a different head that behaves similarly the behavior is still be exhibited:

Plot[{1, ## &[2, 3], 4}, {x, 0, 1}, PlotRange -> {0, 5}, PlotStyle -> Thick]


f[x__] := x

Plot[{1, f[2, 3], 4}, {x, 0, 1}, PlotRange -> {0, 5}, PlotStyle -> Thick]


Plot[{1, {2, 3} /. {x__} :> x, 4}, {x, 0, 1}, PlotRange -> {0, 5}, PlotStyle -> Thick]


Plot builds style lists based on the apparent structure of the first argument it is given, before evaluation. List is recognized and elements are styled individually, while generic functions like Table are styled as a whole.

You can see this behavior here, where Sequence acts as a "generic head":

  {1, Sequence[2, 3], 4}, {x, 0, 1},
  PlotRange -> {0, 5},
  PlotStyle -> Thick

Mathematica graphics

On the other hand sub-lists are recognized and styled:

  {1, {2, 3}, 4}, {x, 0, 1},
  PlotRange -> {0, 5},
  PlotStyle -> Thick

Mathematica graphics

You can read my own question about this and Sasha's excellent answer (starting from EDIT 2).

Recommended form for evaluation

I recommend that you use the option Evaluated -> True rather than Evaluate as it (still) localizes the plot variable. See:

share|improve this answer
Clever trick to use Sequence[] to constrain a group to have the same color... :) –  J. M. Feb 14 '12 at 8:40
This is not working anymore in V10 :( I liked it, this however, works: 72929. They not how to handle Sequence but ## &[2, 3] will do! :) –  Kuba Jan 31 at 7:18
@Kuba Thanks for the note; I hadn't yet noticed it. I'll update the answer. –  Mr.Wizard Jan 31 at 7:28

Evaluate simply evaluates your expression which you want to plot. This transforms this one object Table[BesselJ[n, x], {n, 4}] your are give as argument into the several functions. If Plot sees several functions, it knows it can use more colors. Without Evaluate, Plot does not know you have several functions. This comes from the fact, that is has the attribute HoldAll: it does not evaluate your arguments. Without evaluation the first time it sees, that there are several numbers coming out of your function is during the plotting. Then it's too late to color it differently and you get only a single colored plot.

share|improve this answer

Just to strengthen the idea that Plot does not evaluate the expression even with simplest operations

Plot[0 + {Sin[x], Cos[x]}, {x, 0, 2 \[Pi]}, Filling -> Axis]

enter image description here

share|improve this answer

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.