Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is saving an animation as simple as clicking "Save Graphic As..." in the right-click context menu of the animation? It doesn't seem to work for me—the file naming dialog comes up and I click "Save" but no file seems to be created.

I read about using Manipulate and Export, but keep running into errors going this route (like the kernel hanging and Dynamic Update disabling). I'll keep playing with the code, but was hoping there'd be an easier way to save the animation, "WYSIWYG"-style.

Can't save graphic as...

The full code is below:

prices = FinancialData["QCOM", All][[All, 2]]
S[x_] := MovingAverage[prices, x];
F[x_] := MovingAverage[prices, x];
Animate[si = Interpolation[S[s]]; fi = Interpolation[F[f]]; 
 Show[ListPlot[{prices, S[s], F[f]}, 
   PlotStyle -> {RGBColor[0.7, 0.7, 0.7], Blue, Red}, 
   Joined -> {True, True, True}, PlotStyle -> {Thin, Thin, Thin}], 
  Plot[{si[x], fi[x]}, {x, 1, Length[S[s]]}, 
   MeshFunctions -> {(si[#] - fi[#]) &}, Mesh -> {{0}}, 
   MeshStyle -> Directive[Red, PointSize[Large]]], 
  ImageSize -> {480, 300}], {{s, 150}, 150, 1000, 1}, {{f, 79}, 79, 
  460, 1}, AutorunSequencing -> All, AnimationDirection -> Backward]

I'm new to Mathematica; I apologize if I'm missing something obvious...


I tried @Nasser's code, but keep getting this every 10 or so seconds:

Continue waiting

share|improve this question
    
Also, improvements and opinions (whether functional or stylistic) on my code are wholly welcomed, whether as comments or as part of an answer. Thanks. –  Andrew Cheong Aug 28 '13 at 23:24
    
The question is, what do you really want to save? This may be useful. –  Kuba Aug 28 '13 at 23:30
    
I had no problem myself exporting to SWF, but it took about 2-3 minutes. Again, to export to animated gif file, I recommend using the function ManToGif. –  Nasser Aug 28 '13 at 23:43
add comment

1 Answer

up vote 4 down vote accepted

This worked for me:

prices = FinancialData["QCOM", All][[All, 2]];
S[x_] := MovingAverage[prices, x];
F[x_] := MovingAverage[prices, x];

p = Animate[

   si = Interpolation[S[s]];
   fi = Interpolation[F[f]];

   p1 = ListPlot[{prices, S[s], F[f]}, 
     PlotStyle -> {RGBColor[0.7, 0.7, 0.7], Blue, Red}, 
     Joined -> {True, True, True}, PlotStyle -> {Thin, Thin, Thin}];

   p2 = Plot[{si[x], fi[x]}, {x, 1, Length[S[s]]}, 
     MeshFunctions -> {(si[#] - fi[#]) &}, Mesh -> {{0}}, 
     MeshStyle -> Directive[Red, PointSize[Large]]];

   Show[p1, p2, ImageSize -> {480, 300}],

   {{s, 150}, 150, 1000, 1},
   {{f, 79}, 79, 460, 1},
   AutorunSequencing -> All,
   AnimationDirection -> Backward
   ];

This in a new cell

SetDirectory[NotebookDirectory[]];
Export["animation.swf", p]

and now you can run the .swf from the folder.

To make an animated GIF file, better to use Vitaliy Kaurov ManToGif program.

share|improve this answer
    
Thanks; I like your formatting, by the way. Anyway, I keep getting an error (see edit to question) when attempting to export a GIF. Any ideas as to why? I'll try SWF -> GIF next. –  Andrew Cheong Aug 28 '13 at 23:40
    
@Need to use ManToGif to make animated GIF file. Not directly supported in Mathematica for some reason. The above program will do it though very easily. –  Nasser Aug 28 '13 at 23:41
    
Got it working; took a while to generate the graphic. Thank you! ManToGif[p, "animation", 1] does appear to be working for me, but I can live with the SWF for now. –  Andrew Cheong Aug 28 '13 at 23:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.