3
$\begingroup$

I have a complicated plot (originally a ListLogPlot using many options) with now twelve curves and I would like to force the legend to be displayed in one single column.

Here, I tried to formulate a simplified example:

Plot[{Log[x], Log[x + 1], Log[x + 2], Log[x + 3], Log[x + 4], 
Log[x + 5], Log[x + 6], Log[x + 7], Log[x + 8], Log[x + 9], 
  Log[x + 10], Log[x + 11]}, {x, 0, 30}, PlotTheme -> {"Detailed"}, 
 PlotRange -> {{0, 30}, {0, 5}}, LabelStyle -> {Small, Black}, 
 PlotLegends -> 
  Placed[{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", 
    "11"}, {{0.7, 0.1}, {0, 0}}]]

this produces the following picture enter image description here

To my understanding enough space would be available to avoid the second column. And in my original plot the legend consists of a longer description, hence a second column isn't readable anymore.

I assume something like LegendStyle->{"Column",1} would be part of the solution. But I wasn't able to get it working in connection with the usage of Placed.

Any ideas and help are very much appreciated.

$\endgroup$

1 Answer 1

6
$\begingroup$

You are almost there. Use a LineLegend instead.

Plot[
 {Log[x], Log[x + 1], Log[x + 2], Log[x + 3], Log[x + 4], Log[x + 5], 
  Log[x + 6], Log[x + 7], Log[x + 8], Log[x + 9], Log[x + 10], 
  Log[x + 11]
  }, {x, 0, 30}
 , PlotTheme -> {"Detailed"}
 , PlotRange -> {{0, 30}, {0, 5}}
 , LabelStyle -> {Small, Black}
 , ImageSize -> 600
 , PlotLegends -> 
  Placed[LineLegend[
    ColorData[97][#] & /@ Range[12] {"0", "1", "2", "3", "4", "5", 
      "6", "7", "8", "9", "10", "11"}
    , LegendLayout -> {"Column", 1}
    , LegendMarkerSize -> 10
    ], {{0.95, 0.33}}
   ]
 ]

enter image description here

EDIT

Experiment with LegendFunction and adjust other options accordingly.

LegendFunction -> (Framed[#, Background -> White, RoundingRadius -> 4,
     FrameStyle -> LightGray] &)

LegendLayout -> {"ReversedColumn", 1} would make the legend easier to follow.

$\endgroup$
2
  • 1
    $\begingroup$ Perfect! This was exactly what I looked for. I use it with a ListLogPlot, hence I didn't dare to use LineLegend , but it works. $\endgroup$
    – Lea
    Sep 30 at 18:38
  • $\begingroup$ I am glad I was able to help you. Thanks for the accept. $\endgroup$
    – Syed
    Sep 30 at 19:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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