Skip to main content

plotting - How to simulate Placed in workaround for PlotLegends ParametricPlot bug?


I'd like Legended output for call like:


rcap = {Cos[#], Sin[#]} & ;
p1 = ParametricPlot[{Sin[t] rcap[t], Sin[t]^2 rcap[t]}, {t, 0, Pi},
PlotRange -> {-1, 1}, AxesLabel -> {x, y}

, PlotLegends ->
Placed[{"sin(\[Theta])",
"\!\(\*SuperscriptBox[\(sin\), \(2\)]\)(\[Theta])"}, {Right,
Bottom}]
]

But have hit the ParametricPlot has PlotLegends bug detailed in ParametricPlot and PlotLegends don't seem to cooperate .


I applied the list of functions answer to my plot (adding expressions for my labels) like so:


x1 = With[{funcList = {Sin[t] rcap[t], Sin[t]^2 rcap[t]},
labelList = {"sin(\[Theta])",

"\!\(\*SuperscriptBox[\(sin\), \(2\)]\)(\[Theta])"}
}, With[{n = Length@funcList},
Legended[
ParametricPlot[funcList, {t, 0, Pi}, PlotRange -> {-1, 1},
AxesLabel -> {x, y}],
LineLegend[(ColorData[1][#]) & /@ #, labelList[[#]]] &@Range@n]]
]

which does successfully include a legend:


capture of image



however, the placement of the legend text is outside of the image. Is there a way to add Placed like options to the Legended function?



Answer



From Legended >> Details:



enter image description here



x1 = With[{funcList = {Sin[t] rcap[t], Sin[t]^2 rcap[t]}, 
labelList = {"sin(\[Theta])", "\!\(\*SuperscriptBox[\(sin\), \(2\)]\)(\[Theta])"}},
With[{n = Length@funcList},
Legended[ParametricPlot[funcList, {t, 0, Pi}, PlotRange -> {-1, 1}, AxesLabel -> {x, y}],

Placed[LineLegend[(ColorData[1][#]) & /@ #, labelList[[#]]] &@Range@n, {Right, Bottom}]]]]

enter image description here


You can also use PlotLegends instead of Legended as follows:


x1 = With[{funcList = {Sin[t] rcap[t], Sin[t]^2 rcap[t]}, 
labelList = {"sin(\[Theta])", "\!\(\*SuperscriptBox[\(sin\), \(2\)]\)(\[Theta])"}},
With[{n = Length@funcList},
ParametricPlot[funcList, {t, 0, Pi}, PlotRange -> {-1, 1}, AxesLabel -> {x, y},
PlotLegends -> Placed[LineLegend[ColorData[1][#] & /@ Range@n, labelList[[Range@n]]],
{Right, Bottom}]]]]

(* same picture *)

Comments