2

I would like to know how to reduce the vertical spacing between the legends in the PlotLegend option.

In the answer to this similar question in How to change the spacing of line in legend? it suggests using the option "Spacings" in the method LineLegend. However, such an option seems to be abandoned at least in version 12.0, so what would be the way to achieve the same goal similar to the Spacings option now?

user64494
  • 26,149
  • 4
  • 27
  • 56
Haolin Li
  • 41
  • 1

1 Answers1

2

One way is to give a function to the LegendLayout option. The following is an example of using Column[list,alignment,spacing]. The list itself uses Row[] to combine the colored line (or swatch if SwatchLegend[] is used) with the expression, while spacing controls the vertical spacing. The position of the legend itself is controlled by Placed[].

Plot[{Sin[x], Cos[x]}, {x, 0, 5}, 
 PlotLegends -> 
  Placed[
   LineLegend["Expressions", 
    LegendLayout -> (Column[(Row[{#1[[1]], " ", #1[[2]]}] &) /@ #, 
        Left, 0.5] & )], {1, 0.8}]]

enter image description here

Jean-Pierre
  • 5,187
  • 8
  • 15