Simple example

leg = {"Sin[a x]....", "Cos[x]....", "Tan[x].....", "Cot[x]....."};
Plot[{Sin[a x], Cos[x], Tan[x], Cot[x]}, {x, -Pi/2, Pi/2},PlotLegends -> Placed[leg, Below]]    

enter image description here

shows a plot with plotlegend.

I would like to arrange the plotlegend in one row and tried to resize

leg = Map[Style[#, 5] &, {"Sin[a x]....", "Cos[x]....", "Tan[x].....", "Cot[x]....."}];     

without success. The Legends still are arranged in a 2x2 grid!

How can I force the PlotLegend in one row?


  • $\begingroup$ @ Lukas Lang Thanks, PlotLegends -> Placed[LineLegend[leg, LegendLayout -> {"Row", 1}], Below] is the answer! $\endgroup$ Dec 12 '18 at 11:14

There is an option for the LineLegend which controls this feature:LegendLayout -> "Row". This is, however, not enough. It seems that the legend length should, in addition, fit into the image length. If it does not the legend may be still rearranged into a few lines. It started working as soon as I removed two points from the last two legends. I am not quite sure, however, that it is, indeed, related to the image size. Anyway that's what I see:

leg = {"Sin[x]....", "Cos[x]....", "Tan[x]....", "Cot[x]...."};
leg1 = Map[
   Style[#, 5] &, {"Sin[a x]...", "Cos[x]...", "Tan[x]...", 
 Plot[{Sin[x], Cos[x], Tan[x], Cot[x]}, {x, -Pi/2, Pi/2}, 
  ImageSize -> 100*n, 
  PlotLegends -> 
   Placed[LineLegend[If[LEG, leg, leg1], LegendLayout -> "Row"], 
    Below]], Control[{n, 1, 8}], Control[{LEG, {True, False}}]]

enter image description here

Have fun!


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