5
$\begingroup$

I want to put a title to the plotlegends I am using. I get a solution here which says to use PlotLegends -> SwatchLegend[{0, 3.3, 6.7, 10, 13, 17, 20}, LegendLabel -> "mu"]. But I also want to place the legends where I want like using PlotLegends -> Placed[Range[1, 6, 1], {0.2, 0.3}].

How can I do both?

Edit: As the answer was given, the wrapping works, but there is still a problem, i.e my plot looks like this: enter image description here

Where I want to name the legends as "H". But when I do that Swatchlegend thing it becomes like this : enter image description here

I want to keep the markers and colors same. What should I do?

$\endgroup$
1
  • 1
    $\begingroup$ parametricData = Table[100 - t*x^2, {t, .1, .6, 0.1}, {x, 0, 8}]; ListLinePlot[parametricData, PlotMarkers -> Automatic, PlotLegends -> Placed[PointLegend[Automatic, Range[1, 6, 1], LegendLabel -> "H"], {.2, .4}]] ? $\endgroup$
    – cvgmt
    Commented Sep 12, 2020 at 5:24

3 Answers 3

5
$\begingroup$

You are probably looking for PointLegend, but you should provide more details so others can reproduce your results.

mu = {0, 3.3, 6.7, 10, 13, 17, 20};
pl = PointLegend[mu, LegendLabel -> "mu", LegendFunction -> "Frame", 
   LegendLayout -> "Row", LegendMarkers -> Automatic];
fns = Table[n^(1/p), {p, 7}, {n, 10}];
ListLinePlot[fns, PlotMarkers -> Automatic, 
 PlotLegends -> Placed[pl, Top]]

enter image description here

$\endgroup$
4
$\begingroup$

You can wrap Placed around the legend. Here's an example modified from the SwatchLegend documentation:

Plot[{Sin[x], Cos[x]}, {x, 0, 5}, 
   PlotLegends -> Placed[SwatchLegend[{"first", "second"}, 
LegendLabel -> "legend title"], {0.2, 0.3}]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Okay, it gives what I wanted. But there is a problem. I have markers in my plot like triangle, circles tc which came from the 'PlotMarkers-> Automatic' comment. But here all the legend markers are squares. I know there is a option called 'LegendMarkers->' but it doesn't give what I want. $\endgroup$
    – Sahil
    Commented Sep 11, 2020 at 19:40
3
$\begingroup$

You can use PlotLegends - > Placed[labels, Top, Labeled[#, legendlabel, Top] &] .

Using the example input from Tim Laska's answer:

mu = {0, 3.3, 6.7, 10, 13, 17, 20};
fns = Table[n^(1/p), {p, 7}, {n, 10}];

ListLinePlot[fns, PlotMarkers -> Automatic, 
 PlotLegends -> Placed[mu, Top, Labeled[#, Style["mu", 16], Top] &]]

enter image description here

You can further embellish the appearance using the third argument of Placed:

ListLinePlot[fns, PlotMarkers -> Automatic, 
 PlotLegends -> Placed[mu, Top, Panel @ Labeled[#, Style["mu", 16], Top] &]]

enter image description here

ListLinePlot[fns, PlotMarkers -> Automatic, 
 PlotLegends ->  Placed[mu, Top, 
   Framed[#, FrameStyle -> Directive[Thin, Gray], 
       RoundingRadius -> 5, ImageMargins -> 5] & @
     Labeled[#, Style[Row[{Spacer[5], "mu"}], 24, "Section"], {{Top, Left}}] &]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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