1
$\begingroup$

I'm plotting the spherical harmonics on $\phi\in(-\pi,+\pi)$ and $x=\cos\theta\in(-1,+1)$,

Timing@With[{lMax = 4},
  GraphicsGrid[Table[
    ArrayPad[
     Table[ContourPlot[
       Re@SphericalHarmonicY[l, m, 
         ArcCos[x], \[Phi]], {\[Phi], -\[Pi], \[Pi]}, {x, -1, 1}, 
       AspectRatio -> 2/(2 \[Pi])], {m, -l, l}], lMax - l, Graphics[]],
    {l, 0, lMax}]
   , ImageSize -> 1600]
  ]

which produces a 5 row triangle of plots (rows are l, columns are m=-l...+l. It takes about 15 seconds (which, honestly, seems long, but pales in comparison to ComplexPlot).

In constrast, using ComplexPlot

Timing@With[{lMax = 4},
  GraphicsGrid[Table[
    ArrayPad[
     Table[ComplexPlot[
       SphericalHarmonicY[l, m, ArcCos[Im@\[Phi]x], 
        Re@\[Phi]x], {\[Phi]x, -\[Pi] - I, \[Pi] + I}, 
       AspectRatio -> 2/(2 \[Pi]),
       ColorFunction -> "CyclicLogAbsArg"], {m, -l, l}], lMax - l, 
     Graphics[]],
    {l, 0, lMax}]
   , ImageSize -> 1600]
  ]

to produce a similar figure takes substantially longer (1201 seconds). What gives?

A Smaller Example

Consider, for example, just $l=4$, $m=1$. Then, with AbsoluteTiming,

(* ContourPlot Real part *)
AbsoluteTiming@
 ContourPlot[
  Re@SphericalHarmonicY[4, 1, 
    ArcCos[x], \[Phi]], {\[Phi], -\[Pi], \[Pi]}, {x, -1, 1}, 
  AspectRatio -> 2/(2 \[Pi])]

(* ContourPlot Imaginary part *)
AbsoluteTiming@
 ContourPlot[
  Im@SphericalHarmonicY[4, 1, 
    ArcCos[x], \[Phi]], {\[Phi], -\[Pi], \[Pi]}, {x, -1, 1}, 
  AspectRatio -> 2/(2 \[Pi])]

(* Complex Plot *)
AbsoluteTiming@
 ComplexPlot[
  SphericalHarmonicY[4, 1, ArcCos[Im@\[Phi]x], 
   Re@\[Phi]x], {\[Phi]x, -\[Pi] - I, \[Pi] + I}, 
  ColorFunction -> "CyclicLogAbsArg", AspectRatio -> 2/(2 \[Pi])]

These take, 0.84, 0.78, and 127.5 seconds, respectively.

$\endgroup$
7
  • $\begingroup$ Is there a single input for ComplexPlot that runs slow that we can try? I'm not very eager to run your Table command if it takes 1201 seconds. Try for a minimal working example. Also, use AbsoluteTiming instead of Timing. $\endgroup$ – Jason B. Apr 27 at 1:33
  • 1
    $\begingroup$ @JasonB. provided a reduction to a single entry in the table, $l=4$, $m=1$ as the example. Timings are still ~1 second and ~120+ seconds. $\endgroup$ – evanb Apr 27 at 1:40
  • $\begingroup$ With v12.2 on my Mac laptop the ComplexPlot only took 23.6849 seconds $\endgroup$ – Bob Hanlon Apr 27 at 1:47
  • $\begingroup$ I'm on $Version == "12.1.1 for Mac OS x86 (64-bit) (June 19, 2020)". $\endgroup$ – evanb Apr 27 at 1:49
  • $\begingroup$ On my laptop, the small examples take ~ 0.46, 0.57 and 0.39 seconds respectively. The large examples take ~10.5 and 6.3 seconds respectively. 12.2.0 Win 64 $\endgroup$ – ciao Apr 27 at 6:21
0
$\begingroup$

I upgraded to $Version == "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)".

Holding the machine (and, roughly speaking, the load on said machine) fixed, now my small examples take 1.9, 0.8, and 1.4 seconds each, and the "big" examples (the tables for $l=0..4$ and $m=-l..+l$) take 24.2, 21.0, and 15.3 seconds. So the snail's pace does seem to be fixed by upgrading from 12.1.1 to 12.2.0, at least.

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