I get a slow down when using ContourPlot on elements of a large array of messy expressions. That is, if fooArray has 100 elements and I plot the first 3, that's much slower than if fooArray has 3 elements and I plot all 3. This is annoying and I don't know how to get ContourPlot to just select the element BEFORE doing any evaluating (which I suspect is the problem).

Min Workable Example:

fooArray = Table[Sum[Cos[1.0 n j x] Cos[1.0 n k y], {j, 3}, {k, 3}], {n, nmax}];
ContourPlot[fooArray[[1]], {x, -\[Pi], \[Pi]}, {y, -\[Pi], \[Pi]}] //AbsoluteTiming

nmax=1 (* 0.51 sec *)
nmax=100 (* 6.57 sec *)
(* times are small because my computer is zoom zoom fast *)

Is there a way to get the nmax=1 time regardless of the length of fooArray?

  • 3
    $\begingroup$ Would ContourPlot[fooArray[[1]] // Evaluate, {x, -π, π}, {y, -π, π}] help? $\endgroup$ – J. M. will be back soon Oct 18 '18 at 15:36
  • 1
    $\begingroup$ Welp, yup that did it. I swear I tried something like that, and thought it didn't work. I'll file this under "duh." $\endgroup$ – Max Oct 18 '18 at 15:45

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.