I want to send a few Manipulate
Plots
and regular plots
to my advisor in a notebook. I typically Import
data into my notebook to generate plots but when I open my file on a new computer, the regular Plots
stay but the Manipulate
ones are dead, until I Import
the data again. Is there any way I can keep the data inside the notebook so when he "enables dynamic" to open the notebook on his computer, that the Manipulate
plots
become active, just the way the data in regular plots
are not lost ?
2 Answers
SaveDefinitions
would work for you I guess.
Try the below code. Execute, then save the notebook it is in. Kill the kernel with Quit[]
and reopen the notebook. Content is still there and is manipulable without re-executing.
f = ExampleData[{"Text", "GettysburgAddress"}];
Manipulate[
ListPlot[(StringLength /@ StringSplit[f])[[;; ;; i]]],
{i, 1, 5, 1},
SaveDefinitions -> True
]
-
$\begingroup$ In my experience,
SaveDefinitions
is not as reliable asInitialization
, particularly when moving between platforms. $\endgroup$ Oct 7, 2012 at 21:22 -
$\begingroup$ @Sjoerd C. de Vries and Mark McClure. Thanks for both your answers. Since I had to accept one, I went with Sjoreds. Right now I am using
SaveDefinitions
but when I have to make an important presentation, I will not take a chance and useInitialization
. $\endgroup$– AmatyaOct 16, 2012 at 6:48
You could use the Initialization
option of Manipulate
.
Manipulate[DateListPlot[data[[1 ;; k]],
Filling -> Axis, PlotRange -> {0, 40}],
{{k, 10}, 1, Length[data], 1},
Initialization :> (data = FinancialData["FB", All])]
Alternatively, you could store the data in a separate initialization cell. That is create a cell like so:
Manipulate[DateListPlot[data[[1 ;; k]],
Filling -> Axis, PlotRange -> {0, 40}],
{{k, 10}, 1, Length[data], 1}]
And create (anywhere in the notebook) a separate initialization cell like so:
data = FinancialData["FB", All]
Note that this initialization could contain the pre-downloaded data, rather than an import type command. The important issue is that it's cell properties be set to be an initialization cell.
-
$\begingroup$ Using an initialization cell in your alternative method a
Dynamic
will throw errors until thatInitialization
cell is evaluated. The only way I've found around this is to set your notebook to evaluate automatically at open. $\endgroup$– kaleOct 8, 2012 at 1:02 -
$\begingroup$ @kale That sounds believable. For that method, I was envisioning a scenario where the notebook is opened with no
Output
cells - the user could then execute theInput
cells to see the output. The point behind the initialization cell would be to contain long input, such as pre-imported data. $\endgroup$ Oct 8, 2012 at 1:32 -
$\begingroup$ @MarkMcClure Thanks a lot for your answer. I used the
SaveDefinitions
right now and picked it as the accepted answer because that seemed simpler but I will now try your cell initialization method. I'm sorry, I can't believe that it has taken me 8 days to respond. Thanks a lot. $\endgroup$– AmatyaOct 16, 2012 at 6:55