# How to use Dynamic with ArrayPlot or similar inside Manipulate?

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:

Manipulate[
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

Manipulate[
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.

EDIT

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}];
Dynamic@
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.

• Revers ArrayPlot and Dynamic line Dynamic[ArrayPlot[.. – Daniel Huber Jan 9 at 14:52

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]


Edit

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


Original

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

• 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, – Russ Lyons Jan 9 at 1:59
• 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. – Russ Lyons Jan 9 at 2:11
• The suggestion to use With will not allow further change of data; the final values would have to be set within the initial assignment. – Russ Lyons Jan 9 at 18:50
• @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”. – CA Trevillian Jan 10 at 5:07
• @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. – Russ Lyons Jan 10 at 15:40