Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am wondering if one can place on the right of the plot frame a single legend that is a combination of a LineLegend and a SwatchLegend.

What I want is to see the line with its label on top of the swatch with its label as if the swatch was the second item of a LineLegend.

I have tried

 PlotLegends -> {LineLegend[{Blue}, {"first item"}, 
     LabelStyle -> {Bold, 20}], 
     SwatchLegend[{Opacity[0.3, Blue]}, {"second item"}]}

and some variations with Join[] but I have not succeded to put all these legends on the right of the frame. For instance the code above places one legend on the right and one at the bottom, which is not what I want.

Is this merge possible or I should write something from scratch?

Thanks for your inputs, Roberto

share|improve this question

Additional alternatives to mix different legends:

lg1 = SwatchLegend[{Red}, {"sin"}];
lg2 = LineLegend[{Blue}, {"cos"}];
lg3 = PointLegend[{Green}, {"sinc"},   LegendMarkers -> "\[FilledCircle]"];

Plot[{Sin[x], Cos[x], 2 Sinc[x]}, {x, -2 Pi, 2 Pi},
     PlotStyle -> Thread[{Thick, {Red, Blue, Green}}], ImageSize -> 400,
     PlotLegends -> (Placed[#, Right] & /@ {lg1, lg2, lg3})]

enter image description here

or PlotLegends -> {{lg1, Right}, {lg2, Right}, {lg3, Right}}

or PlotLegends -> Column[{lg1, lg2, lg3}]] (as in Roberto's answer)

And a few alternative ways to use Legended in addition to the method in ubpdqn's answer:

Legended[Plot[{Sin[x], Cos[x], 2 Sinc[x]}, {x, -2 Pi, 2 Pi},
   PlotStyle -> Thread[{Thick, {Red, Blue, Green}}], ImageSize -> 400], 
   (Placed[#, Right] & /@ {lg1, lg2, lg3})]

Alternatively, use Column[{lg1, lg2, lg3}]] or {{lg1, Right}, {lg2, Right}, {lg3, Right}} in the second argument of Legended.

share|improve this answer

Perhaps this contrived example will be helpful:

lleg = LineLegend[{Red}, {"sin"}];
sleg = SwatchLegend[{Blue}, {"cos"}];
Legended[Show[Plot[Sin[x], {x, 0, 2 Pi}, PlotStyle -> Red], 
  ListPlot[Table[{j, Cos[j]}, {j, 0 , 2 Pi, 0.11}]]], 
 Framed[Column[{lleg, sleg}], RoundingRadius -> 10, 
  Background -> LightBlue]]

enter image description here

share|improve this answer

The legends need to go into a Column[] ...

 PlotLegends -> 
  Column[{LineLegend[{Blue}, {"First"},], 
   SwatchLegend[{Opacity[0.3, Blue]}, {"Second"}, 
share|improve this answer

Your Answer


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.