Some alternatives ideas. Plots, especially 3D plots, can be quite large. The list of plots below are around 165K. Some of the Manipulate
cells that store the plots are around 670K. The one with plots in external file are 4-5K, but have to read the data in. These sizes are not large enough to cause problems with the responsiveness of the front end. So it's mainly a question of style. Other advantages of some solutions: automatic initialization of the plots; persistent initialization (no re-initialization needed when Mathematica restarts); localization of variables; shareability.
Save in an external, shareable file
To share, send both the notebook and the file listOfPlots.mx.
DumpSave[FileNameJoin[{NotebookDirectory[], "listOfPlots.mx"}],
listOfPlots];
Manipulate[
If[! ListQ[listOfPlots],
Get[FileNameJoin[{NotebookDirectory[], "listOfPlots.mx"}]]
];
listOfPlots[[i]],
{i, 1, Length@LocalSymbol["listOfPlots"], 1}
]
Save in an external, local file
Must initialize the local symbol (once!) before Manipulate
will work. One could use CloudSymbol[]
, if one wants a cloud-based solution, which would make the list of plots accessible to other computers.
If[! ListQ[LocalSymbol["listOfPlots"]],
LocalSymbol["listOfPlots"] =
Table[Plot[Cos[b x], {x, -1, 1}], {b, 1, 9}]
];
Manipulate[LocalSymbol["listOfPlots"][[i]],
{i, 1, Length@LocalSymbol["listOfPlots"], 1}
]
Local file initialized in Manipulate
The initialization happens only once, after which the Manipulate
operates smoothly. One can remove the local symbol first, to check initialization.
(*LocalSymbol["listOfPlots"]//Remove;*)
Manipulate[
Dynamic[
If[ListQ@LocalSymbol["listOfPlots"],
LocalSymbol["listOfPlots"][[i]],
"please wait"],
SynchronousUpdating -> True],
{i, 1, Length@LocalSymbol["listOfPlots"], 1},
Initialization :> (
If[! ListQ[LocalSymbol["listOfPlots"]],
LocalSymbol["listOfPlots"] =
Table[Pause[1]; Plot[Cos[b x], {x, -1, 1}], {b, 1, 9}]
];),
SynchronousInitialization -> False
]
Gussied up version, with a progress indicator.
Manipulate[
Dynamic[
If[ListQ@LocalSymbol["listOfPlots"],
(*** MAIN BODY ***)
LocalSymbol["listOfPlots"][[i]]
(*** END BODY ***)
, If[! initializing,
Button["Click to initialize plots",
initializing = True;
LocalSymbol["listOfPlots"] =
Table[
Pause[1]; Plot[Cos[b x], {x, -1, 1}],
{b, 1, 9}];
initializing = False,
Method -> "Queued"
],
Dynamic@Column[{
Row[{"Computing plot ", b}],
ProgressIndicator[b/10.]
}]
]],
SynchronousUpdating -> True],
(*** VAR DECLARATIONS ***)
{i, 1, Length@LocalSymbol["listOfPlots"], 1},
{{initializing, False}, None}, {b, None}
]
Plots stored in notebook in Manipulate
The variable listOfPlots
is also localized in Manipulate
and not a global variable (generally an advantage, unless you need the variable to be accessible both inside and outside Manipulate
).
With[{listOfPlots0 = Table[Plot[Cos[b x], {x, -1, 1}], {b, 1, 9}]},
Manipulate[listOfPlots[[i]],
{i, 1, Length@listOfPlots, 1},
{{listOfPlots, listOfPlots0}, None}]
]
One can use Iconize
, if you "Evaluate in Place" (see Evaluation menu) to convert to an icon.
Manipulate[listOfPlots[[i]],
{i, 1, Length@listOfPlots, 1},
{{listOfPlots, Iconize@Table[Plot[Cos[b x], {x, -1, 1}], {b, 1, 9}]},
None}]
Manipulate[listOfPlots[[i]], {i, 1, Length@listOfPlots, 1}]
to display the one you want. $\endgroup$