3
$\begingroup$

I have a plot whose legend, when placed at the bottom, is two lines rather than one:

Plot[{x, x^2}, {x, 0, 5}, PlotRange -> {0, 5}, PlotLegends -> Placed[Abs /@ {Subscript[a, 2]/Subscript[a, 1], Subscript[a, 3]/Subscript[a, 1]}, Below]]

If I do the same thing without the absolute value signs, it plots in a row as I'd like:

Plot[{x, x^2}, {x, 0, 5}, PlotRange -> {0, 5}, PlotLegends -> Placed[{Subscript[a, 2]/Subscript[a, 1], Subscript[a, 3]/Subscript[a, 1]}, Below]]

I'm guessing the absolute value signs make this slightly too wide, but putting the two legends side by side would clearly fit into the plot. I've spent a while digging through the documentation and cannot figure out how to do this - help would be appreciated!

$\endgroup$
1
  • 1
    $\begingroup$ nice to meet you here :) $\endgroup$
    – Yi Wang
    Jul 19, 2014 at 16:24

3 Answers 3

3
$\begingroup$

I think it may be a bug. One can explicitly specify the layout of plot, for example,

LineLegend[{Red, Blue}, {Abs[Subscript[a, 2]/Subscript[a, 1]], 
  Abs[Subscript[a, 3]/Subscript[a, 1]]}, 
 LegendLayout -> (Grid[{Flatten@#}] &)]

And here is the plotting function applying the above method:

Plot[{x, x^2}, {x, 0, 5}, 
 PlotLegends -> 
  Placed[LineLegend[
    Abs@{Subscript[a, 2]/Subscript[a, 1], 
      Subscript[a, 3]/Subscript[a, 1] }, 
    LegendLayout -> (Grid[{Flatten@#}] &)], Below ]]
$\endgroup$
4
$\begingroup$

LegendLayout -> {"Row", 1}

The option LegendLayout -> {"Row", 1} gives the desired result:

legend = LineLegend[Automatic, Abs /@ {Subscript[a, 2]/Subscript[a, 1], 
     Subscript[a, 3]/Subscript[a, 1]}, LegendLayout -> {"Row", 1}];

Plot[{x, x^2}, {x, 0, 5}, PlotRange -> {0, 5}, PlotLegends -> Placed[legend, Below]]

enter image description here

$\endgroup$
2
$\begingroup$

This is not quite satisfactory but at least a row:

row[p_] := 
 TableForm[p, TableAlignments -> Center, TableDirections -> Row]

leg :=
 LineLegend[{Orange, Blue},
  {TraditionalForm[Abs[Subscript[a, 2]/Subscript[a, 1]]],
   TraditionalForm[Abs[Subscript[a, 3]/Subscript[a, 1]]]},
  LegendLayout -> row]

Plot[{x, x^2}, {x, 0, 5},
 PlotRange -> {0, 5},
 PlotLegends -> Placed[leg, Below]]
$\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.