While trying to analyse several different datasets I got what I thought was a good idea: define a "function" that returns a Manipulate
object. But this has some problems when larger amounts of data are passed to Manipulate
. When the code is first run there is long delay before the manipulate pane is displayed, because the the data gets embedded inside "Body"
of Manipulate
.
Here is a code snippet that illustrates the problem:
(*Generate some data*)
data = RandomVariate[BinormalDistribution[Abs@Random[]], {5, 10^4}];
histograms = DensityHistogram[#, 30, PerformanceGoal -> "Speed"] & /@ data;
images = Rasterize[#, ImageSize -> Medium] & /@ histograms;
AnalysePlots[plots_] :=
Manipulate[plots[[i]], {i, 1, Length[plots], 1}];
(*Now compare:*)
t = AbsoluteTime[];
AnalysePlots[images] // AbsoluteTiming
AbsoluteTime[] - t
(* ==>3.7091792<---HERE IMAGES GET EMBEDDED*)
t = AbsoluteTime[];
Manipulate[images[[i]], {i, 1, Length[images], 1}] // AbsoluteTiming
AbsoluteTime[] - t
(* ==>0.0312500<---Here they don't*)
Can I somehow choose whether to embed the data (in this case the variable plots) into Manipulate
?
When developing the function AnalysePlots
it would be nice if I could do something like:
AnalysePlots[images, "Embed"->False]
which would have the benefit of displaying quickly. Then when I've finished AnalyzePlots
I would deploy it with:
AnalysePlots[images, "Embed"->True]
which I could then copy and paste to a new notebook, deploy to CDF etc...
(I've already tried SaveDefinitions->False
and UnsavedVariables :> {plots}
)
Manipulates
via functions. Because this starts very quickly: Manipulate[rasterizedSmall[[i]], {i, 1, Length[rasterizedSmall], 1}] $\endgroup$