Re: Slow Manipulate with image argument
- To: mathgroup at smc.vnet.net
- Subject: [mg79215] Re: Slow Manipulate with image argument
- From: Albert <awnl at arcor.net>
- Date: Sat, 21 Jul 2007 04:27:16 -0400 (EDT)
- References: <f7pqi0$1a8$1@smc.vnet.net>
Maarten van der Burgt wrote: > Dear all, > > > > > > Consider the lines of code below: > > > > dat =Table[Sin[x y/2],{x,-10,10,0.04},{y,-10,10,0.04}]; > > gr=ArrayPlot[dat]; > > h=Length[dat]; > w =Length[dat[[1]]]; > > Manipulate[ > GraphicsColumn[{Show[{gr,Graphics[{Green,Line > [{{0,h-i},{w,h-i}}]}]}],ListPlot[dat[[i]],PlotJoined->True,PlotRange-> > {-1,1}]}], > {{i,200},1,h,1}] > > > In the code above I generate a quite large array with data (= dat; in my > real application dat is an image of similar size which I want to analyze). > > > I generate an ArrayPlot (gr) of the data. > > > Using Manipulate I want to show the data in each line of the array using > ListPlot. > > > It would help the analysis if in the same Manipulate window I could show > the image with a line drawn on top of it, indicating which line of the > array is shown in the ListPlot. > > > This all works, but, since the graphics needs to be updated every time, > Manipulate becomes very slow. > > > Has anyone a bright idea how to speed this up, or to write this slightly > different with the same (but faster) result? the trick is to only dynamically update those parts which are really changing which can be done by wrapping those parts with Dynamic within the Manipulate. More about how to do that is described in the tutorial advanced dynamic something (I think it is one of the things that are not too hard to find in the new documentation). The tricky part is that Show obviously doesn't like to show Dynamic[]s, so you have to do the job of Show by yourself. Here is one version with Inset, which has the disadvantage that you need a lot of definitions where to place and which part to show, but it works and is reasonable reactive. With some more effort you can probably make it somewhat less verbose about all those plotranges etc... Manipulate[GraphicsColumn[{ Graphics[{ Inset[gr, {-10, -10}, {-10, -10}, 20], Green, AbsoluteThickness[5], Dynamic[Line[{{-10, -10 + 20 (h - i)/h}, {10, -10 + 20 (h - i)/h}}]]}, PlotRange -> {{-10, 10}, {-10, 10}} ], Dynamic[ListPlot[dat[[i]], Joined -> True, PlotRange -> {-1, 1}]] }], {{i, 200}, 1, h, 1}] hth, albert