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.

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}]]

Mathematica graphics

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?

share|improve this question
    
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) –  kguler 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
add comment

3 Answers 3

up vote 2 down vote accepted

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]]]

enter image description here

share|improve this answer
add comment

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}]
]

enter image description here

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"
 ]
*)
share|improve this answer
1  
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

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.