4
$\begingroup$

How can I change the gap (marked by the double arrow below) between a frame and a plot legend?

DensityPlot[Sin[x + y^2], {x, 0, 2 Pi}, {y, 0, 2 Pi},
  PlotPoints -> 100, 
  PlotLegends -> Placed[Automatic, Right]]

enter image description here

I tried to use Placed, but the result was same as Placed -> {Automatic, Right}.

$\endgroup$
2
$\begingroup$

You can remove the margins from around the legend by setting LegendMargins to 0, and use the form $\{\{e_x, e_y\},\{l_x,l_y\}\}$ for pos in Placed[legend, pos].

From Legended >> Details

enter image description here

For example, setting $l_x = .1$ we get:

DensityPlot[Sin[x + y^2], {x, 0, 2 Pi}, {y, 0, 2 Pi}, 
  PlotPoints -> 100, ImageSize -> Medium,
  PlotLegends -> Placed[BarLegend[Automatic, LegendMargins -> 0] , 
     {{1, .5}, {0.1, .5}}]]

enter image description here

$\endgroup$

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.