# How to get rid of the white margins in picture export?

I made a manipulate box to show some spherical harmonics decomposition, and everything is working great (but it's very slow, when I add more harmonics!). Then I need to export the picture, without any axis, frame and margins. The MWE below is doing what I need, but I still get a white margin all around the exported picture. How can I get rid of the white margins, in the exported picture?

LegFunc[n_, m_, theta_] := Sqrt[((2 n + 1)/(4 Pi))((n - m)!/(n + m)!)]LegendreP[n, m, Cos[theta]]

testF[theta_, phi_, a10_, a11_, alpha11_] := a10 LegFunc[1, 0, theta] + 2 a11 LegFunc[1, 1, theta] Cos[1 phi + alpha11]

Manipulate[
graphTest = DensityPlot[
testF[theta, phi, a10, a11, alpha11],
{phi, 0, 2 Pi}, {theta, 0, Pi},
PlotPoints -> {ControlActive[20, 50], ControlActive[10, 30]},
PlotRange -> {{0, 2 Pi}, {0, Pi}},
Axes -> True,
AxesOrigin -> {Pi, Pi/2},
AxesStyle -> Directive[GrayLevel[0.5], Dashed],
Frame -> True,
FrameLabel -> {
Style["\[CurlyPhi]", Bold, 14],
Style["\[CurlyTheta]", Bold, 14]
},
FrameTicks -> {{0, Pi, 2 Pi}, {0, Pi/2, Pi}},
ColorFunction -> ColorData["Rainbow"],
AspectRatio -> Automatic,
ImageMargins -> 0,
ImageSize -> 800
],
{{a10, 0.5, a10}, 0, 1, 0.05}, {{a11, 0.5, a11}, 0, 1, 0.05}, {{alpha11, Pi/2, \[Phi]11}, 0, 2 Pi, 0.1 Pi},
FrameMargins -> None,
FrameLabel -> {None, None,
Style["Some Funny Title", Bold, 14, FontFamily -> "Helvetica"]}
]


The command below exports the picture without any frame or axis, but still leaves a pesky white margins that I need to remove:

Export["~/Desktop/graphictest.png", graphTest[[1]] // Graphics, ImageSize -> {2048, 1024}]


I could add the command Background -> None, but then the image is smaller than the size asked, with a transparent margin.

• \[Phi]11 is not defined. Is it a typo?? Apr 6 '21 at 16:21
• @DanielHuber, this is the symbol displayed in the manipulate box.
– Cham
Apr 6 '21 at 16:33
• Export this Graphics[graphTest[[1]], PlotRangePadding -> None] Apr 6 '21 at 16:45
• @BenIzd, it works, but I’m getting a white line below the picture, and also on its right. Why is that?
– Cham
Apr 6 '21 at 16:52
• Export this Graphics[graphTest[[1]], PlotRangePadding -> None, ImagePadding -> None] :D Apr 6 '21 at 17:19