I have some complicated data to calculate and display. I want to change the display inside Manipulate with a control variable and use Dynamic to avoid recalculating the data. For example, Mma documentation gives this, which works beautifully:

 data = RandomReal[{0, 1}, {n, 2}];
 Graphics[{Point[Dynamic[data^p]]}, AspectRatio -> 1], {n, 100, 5000, 
  1}, {p, 0.1, 10}, SynchronousUpdating -> False]

But if I try

 data = RandomReal[{0, 1}, {2, 2}];
 ArrayPlot[Dynamic[data^p]], {p, 0.1, 10}, SynchronousUpdating -> False]

it gives an error. The same happens with (List)DensityPlot. It will not work either if I try to just change the ColorFunction inside Dynamic. Nor do I see how to recalculate what to plot outside the Plot but inside a Dyanmic.


I need to Show the ArrayPlot together with a Graphics object. For example, this does not work:

Manipulate[data = RandomReal[{0, 1}, {2, 2}];
 Show[Dynamic@ArrayPlot[data^p], Graphics[Circle[]]], {p, 0.1, 10}, 
 SynchronousUpdating -> False]

Second edit

The real problem seems to be that I have a Block inside my Manipulate, and then the local variable I use for data turns red when I try to put it inside a Dynamic, indicating it may not work even before I try. Example:

Manipulate[Module[{data}, data = RandomReal[{0, 1}, {2, 2}];
   Show[ArrayPlot[data^p], Graphics[Circle[]]], {p, 
  0.1, 10}, SynchronousUpdating -> False]

I have discovered that it is impossible to update local variables; see this doc. I have asked another question specific to this issue here.

  • $\begingroup$ Revers ArrayPlot and Dynamic line Dynamic[ArrayPlot[.. $\endgroup$ Jan 9, 2021 at 14:52

1 Answer 1


New Edit

Maybe use With

Manipulate[With[{data = RandomReal[{0, 1}, {2, 2}]},
  Dynamic@Show[ArrayPlot[data^p], Graphics[Circle[]]]], {p, 0.1, 10}, 
 SynchronousUpdating -> False]


Manipulate[data = RandomReal[{0, 1}, {2, 2}];
 Dynamic@Show[ArrayPlot[data^p], Graphics[Circle[]]], {p, 0.1, 10}, 
 SynchronousUpdating -> False]


Manipulate[data = RandomReal[{0, 1}, {2, 2}];
 Dynamic@ArrayPlot[data^p], {p, 1, 10}, SynchronousUpdating -> False]
  • $\begingroup$ Thank you for the very fast answer. In fact, I need to edit my question, because I need to Show the ArrayPlot together with a Graphics object, and your answer will not work, $\endgroup$
    – Russ Lyons
    Jan 9, 2021 at 1:59
  • $\begingroup$ Your edited response is also correct and very fast, but, again, I need to modify my question. I tried to make it as simple as possible, but evidently I have not yet captured the real difficulty. When I figure it out, I will edit again. $\endgroup$
    – Russ Lyons
    Jan 9, 2021 at 2:11
  • $\begingroup$ The suggestion to use With will not allow further change of data; the final values would have to be set within the initial assignment. $\endgroup$
    – Russ Lyons
    Jan 9, 2021 at 18:50
  • 1
    $\begingroup$ @RussLyons there is nothing preventing this when using With. It would make for better responses if you can be more clear about what you mean when you say “the final values” and to clarify how you would like to have a “change of data”. $\endgroup$ Jan 10, 2021 at 5:07
  • $\begingroup$ @CATrevillian I think you are right. I can compute data, then use With[{d=data} ... d ...] with a new dummy variable d and not use data in the plot. Thanks. $\endgroup$
    – Russ Lyons
    Jan 10, 2021 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.