# ParametricPlot and PlotLegends don't seem to cooperate

Bug introduced in 9.0.1 -- fixed in 10.0.0?

I noted that only part of the legend shows up in ParametricPlot using v9's PlotLegends:

ParametricPlot[{{t, t}, {t, 2 t}}, {t, 0, 1}, PlotLegends -> LineLegend[{1, 2}]]


Inspecting the figure's FullForm gets me (among other things)

LineLegend[
List[
Directive[EdgeForm[GrayLevel[0.5]], Hue[0.9060679774997897, 0.6, 0.6]]
], List[1, 2],
Rule[LegendLayout, "Column"]]


It looks like Mathematica forgot to add the second color. Adding the color manually gets me the full legend. This looks like a bug, but perhaps I'm missing something?

I also noticed that virtually all examples in the "Options/PlotLegends" section of the ParametricPlot doc page yield a result differing from the pre-rendered image. Again, this looks like a bug, perhaps introduced by a last-minute addition. I'm using v9.0.1. Anyone with v9.0.0 care to check whether it exists there as well?

• The problem seems to be that the plot legends code is not parsing the first argument to ParametricPlot correctly and identifying the different functions. It incorrectly lists all the terms as a single entry and this can be seen by setting PlotLegends -> "Expressions". In essence, the bug is the equivalent of plotting 2 curves but labeling only 1 (but somewhere inside, the code does know that there are 2 curves, since the line color is pink) – rm -rf Mar 11 '13 at 23:27
• Both legends show as expected in Version 9.0.0 (on Windows Vista 64 bit) – kglr Mar 11 '13 at 23:42
• And legends show as expected if you use this old method with autoLegend... – Jens Mar 11 '13 at 23:46
• @kguler So, as hypothesized, something added in the latest update breaks PlotLegends in this case. – Sjoerd C. de Vries Mar 13 '13 at 8:40
• If you have 10.0.0 installed would you please check to see if this was fixed in that release? – Mr.Wizard Jan 29 '15 at 10:24

The work-around posted by rcollyer can readily be generalized to work for an arbitrary number of parametric functions.

With[{funcList = {{t, t}, {t, 2 t}, {t, t/2}}},
With[{n = Length@funcList},
Legended[ParametricPlot[funcList, {t, 0, 1}],
LineLegend[(ColorData[1][#])& /@ #, #]& @ Range @ n]]]


To flesh out your method, you can do the following

Legended[
ParametricPlot[{{t,t},{t,2 t}},{t,0,1}],
LineLegend[{ColorData[1][1], ColorData[1][2]}, {1, 2}]
]


which, as noted, requires you to set the color information by yourself. This is the most straightforward workaround.

Incidentally, it is often cleaner to look at the InputForm instead of the FullForm as things like List are not fully expanded. For this, I often use something like this,

Plot[{x^2, x^3}, {x, 0, 1}, PlotLegends -> Automatic] /.
Legended[_, {p_Placed, ___} | p_Placed]:> InputForm@p[[1]]

(*
LineLegend[{Directive[Hue[0.67, 0.6, 0.6]],
Directive[Hue[0.9060679774997897, 0.6, 0.6]]}, {1, 2},
LegendLayout -> "Column"
]
*)

• Apparently, Wolfram tech support was wrong when they told me "there is no good way of working around the problem". – m_goldberg Mar 13 '13 at 4:12
• @m_goldberg This was the line of solution I was hinting at in my question. – Sjoerd C. de Vries Mar 13 '13 at 8:33
• @rcollyer I have the habit of using FullForm because that's the form that will be used in pattern matching, but I agree that InputForm is often much clearer and is preferable when one just wants to see what's going on. – Sjoerd C. de Vries Mar 13 '13 at 8:35
• @m_goldberg don't necessarily blame them, I've been staring at this particular code for quite a while, so I have a good feel for how it works. – rcollyer Mar 13 '13 at 11:43
• @SjoerdC.deVries I had the same habit until I had to start looking at Graphics objects. FullForm would drive you insane pretty quickly. – rcollyer Mar 13 '13 at 11:46

I queried Wolfram technical support on this issue. Here is their reply:

Our developers are aware that PlotLegends is currently not working well with ParametricPlot. This problem should be fixed in a future version of Mathematica.

Unfortunately, there is no good way of working around the problem with PlotLegends at the current time. If you really need a legend with a ParametricPlot, you might have to use the older PlotLegend function, which is still available in Mathematica.

• Seems to be fixed in Version 10!? -> link – Phab Jan 29 '15 at 8:05

As noted by Phab the example in the question works in Mathematica 10.0.2:

ParametricPlot[{{t, t}, {t, 2 t}}, {t, 0, 1}, PlotLegends -> LineLegend[{1, 2}]]


• I arrived at this thread after observing a similar problem in 10.1.0. PlotLegends->Automatic gives up after 15 curves. Fortunately, I can still make the legends show correctly with PlotLegends->LineLegend[Range[n]] for n at least as big as 26. – djphd Dec 7 '15 at 20:20
• @djphd Indeed, that is a known issue. The limitation is not arbitrarily fifteen, but rather the number of colors in the style. Please see (66057) for more. – Mr.Wizard Dec 8 '15 at 1:05