Consider this example:

Plot[Table[BesselJ[n, x], {n, 2}], {x, 0, 10}, 
 PlotLegends -> {"n=1", "n=2"}, Evaluated -> True]

The results in MMA v9 & V10 are:


enter image description here


enter image description here

Any idea why V10 can't pick up all PlotLegends? Thanks.

  • 3
    $\begingroup$ Probably a(nother) bug $\endgroup$ – Dr. belisarius Dec 15 '14 at 19:28
  • 1
    $\begingroup$ Evaluate does work: Plot[Evaluate@Table[BesselJ[n, x], {n, 2}], {x, 0, 10}, PlotLegends -> {"n=1", "n=2"}], which is also a workaround. $\endgroup$ – Jacob Akkerboom Dec 15 '14 at 19:38
  • 2
    $\begingroup$ For me it is still undocumented so I would not call it a bug :) $\endgroup$ – Kuba Dec 15 '14 at 19:43
  • $\begingroup$ @Kuba, the case here is V9 and V10 giving two different results. it may be good to call it bug -:) $\endgroup$ – Algohi Dec 15 '14 at 19:47
  • $\begingroup$ @Algohi I can't agree. Even mod would not ;) $\endgroup$ – Kuba Dec 15 '14 at 20:06

I am in the middle of the long process of Tracing this issue. I don't yet have a patch but I can point to a part of the code that affects this. The function is:


Within its long definition we have a piece:

Legending`LegendDump`length = Switch[Legending`LegendDump`tag,
  0, Legending`LegendDump`optDimensions,
  _Integer, Legending`LegendDump`optDimensions[[Legending`LegendDump`tag]],
  If[Legending`LegendDump`arglength === Null, Switch[Legending`LegendDump`argexp,
    Null, 0,
    _List, Length[Legending`LegendDump`argexp],
    _, 1], Legending`LegendDump`arglength]]

This is where the number of functions is determined for the sake of legend generation. The critical part here is:


Which in the case of the example in the question expands to:

Length[{HoldForm[Table[BesselJ[n, x], {n, 2}]]}]

The plot function is being passed unevaluated (held by HoldForm) to Legending`LegendDump`plotLegendParser, which is exactly the sort of problem I expected. I have confirmed that replacing Length[. . .] in this definition with 2 causes the legend to be draw properly for this example, but I have not yet figured out how to determine that value automatically.

This answer is a work in progress but I wanted to get this down before I forget it. It may also serve as a starting point for anyone else who wishes to tackle the problem.


Not really an idea or insight, but a workaround (on 10.0 for Mac OS X x86 (64-bit) (September 10, 2014);

Plot[Table[BesselJ[n, x], {n, 2}], {x, 0, 10},  
 PlotStyle -> {Red, Blue},  
 PlotLegends -> LineLegend[{Red, Blue}, {"n=1", "n=2"}],  
 Evaluated -> True]

enter image description here

The "Help" is not really a help:

enter image description here enter image description here

except the workaround I can not offer an explanation for this behavior.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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