# Why is ComplexPlot So Slow?

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

Timing@With[{lMax = 4},
GraphicsGrid[Table[
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[
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.

• 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. – Jason B. Apr 27 at 1:33
• @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. – evanb Apr 27 at 1:40
• With v12.2 on my Mac laptop the ComplexPlot only took 23.6849 seconds – Bob Hanlon Apr 27 at 1:47
• I'm on $Version == "12.1.1 for Mac OS x86 (64-bit) (June 19, 2020)". – evanb Apr 27 at 1:49 • 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 – ciao Apr 27 at 6:21 ## 1 Answer 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.