0
$\begingroup$

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,
   PlotRangePadding -> 0,
   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.

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

Your Answer

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

Browse other questions tagged or ask your own question.