0
$\begingroup$

I am trying to reduce the space between my plot's FrameLabel, which is in the form of a LineLegend, and the top of the plot's frame. Is there an easy way to do this? A simplified version of my code is:

Plot1 = Plot[1000*Exp[-0.03*t], {t, 0, 100}, 
  ImageSize -> Automatic -> Medium, PlotStyle -> {Black}, 
  PlotRange -> {0, 1}, Frame -> {{True, True}, {True, True}}, 
  FrameLabel -> {None, None, 
    LineLegend[{Gray, Red, Black}, {"test1", "test2", "test3"}, 
     LegendLayout -> {"Row", 1}, 
     LegendMarkers -> {{"\[FilledSquare]", 
        20}, {"\[FilledUpTriangle]", 20}, {"\[FilledCircle]", 20}}]}]
$\endgroup$
1
  • 1
    $\begingroup$ Add LegendMargins -> 0? $\endgroup$
    – Syed
    Oct 21, 2022 at 18:35

1 Answer 1

2
$\begingroup$
p1 = Plot[1000*Exp[-0.03*t]
  , {t, 0, 100}
  , ImageSize -> Automatic -> Medium
  , PlotStyle -> {Black}
  , PlotRange -> {0, 1000}
  , Frame -> {{True, True}, {True, True}}
  , FrameLabel -> {{None, None}, {None, None}}
  , ImagePadding -> {{40, 10}, {30, 10}}
  ];

g1 = Graphics[
  Inset[
   LineLegend[{Gray, Red, Black}
    , {"test1", "test2", "test3"}
    , LegendLayout -> {"Row", 1}
    , LegendMarkers -> {{"\[FilledSquare]", 
       20}, {"\[FilledUpTriangle]", 20}, {"\[FilledCircle]", 20}}
    , LegendMargins -> 0
    ]
   , {50, 1000}
   ]
  , PlotRange -> {{0, 100}, {995, 1005}}
  ];

Grid[{{g1}, {p1}}, Spacings -> {0, -0.4}]

enter image description here

$\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.