18
$\begingroup$

I am using the following example code to export Manipulate to GIF:

ManToGif[man_, name_String, step_Integer] := Export[name <> ".gif", Import[Export["f:\\test.avi", man], "ImageList"][[1 ;; -1 ;; step]]] man = Manipulate[Plot[Sin[x], {x, 0, end}], {end, Pi, 2 Pi, 0.1}]; ManToGif[man, "f:\\test", 1]; 

Is there another possibility to do that? How can I see the value of the variable end?

You see at bottom of the movie some strange black bars and also at the right edge a black vertical line, which should not be there.

enter image description here

$\endgroup$
7
  • $\begingroup$ Why don't you press that + toggler to open the additional control bar? It includes InputField which shows how the value updates. $\endgroup$ Commented Aug 11, 2016 at 12:55
  • 6
    $\begingroup$ Or, programmatically, {end, Pi, 2 Pi, 0.1, Appearance -> "Open"}. $\endgroup$ Commented Aug 11, 2016 at 12:56
  • 1
    $\begingroup$ Those are not "strange black bars", those are the background. If you want to avoid showing the background you need to control the size of the plot so that it covers the same area at all time. $\endgroup$ Commented Aug 11, 2016 at 12:59
  • $\begingroup$ closely related: How to Export this animation as a gif file $\endgroup$ Commented Aug 11, 2016 at 13:01
  • 1
    $\begingroup$ @mrz - I still got a bit of movement in the axes until I added the option ImagePadding -> 10, now I get this. Another option would be to give ImageSize two numbers, so that the width and height are always specified. $\endgroup$ Commented Aug 11, 2016 at 14:16

2 Answers 2

15
$\begingroup$

You can do this outside of the manipulate box and show the variable's value as a legend. Also by using fixed image sizes and aspect ratios you can minimize the occurrence of black bars as the variables change.

First Step: Make a table of your desired Plots, I think the code here is relatively easy to understand:

Anim = Table[ Plot[Sin[x], {x, 0, t}, PlotRangePadding -> 0.1, ImageSize -> 500, AspectRatio -> 1/2, PlotLegends -> TextString@Row@{"T=", t}] , {t, Pi, 2 Pi, .1} ]; 

Second Step: Export it as a GIF image :)

Export["anim.gif", Anim] 

Final Result:

enter image description here

Hope it's suitable for what you have in mind ;)

UPDATE

If you want it to move forward an then backward you can make tables of the animation for each direction and join them:

Anim1 = Table[ Plot[Sin[x], {x, 0, t}, PlotRangePadding -> 0.1, ImageSize -> 500, AspectRatio -> 1/2, PlotLegends -> TextString@Row@{"T=", t}] , {t, Pi, 2 Pi, .1} ]; Anim2 = Table[ Plot[Sin[x], {x, 0, t}, PlotRangePadding -> 0.1, ImageSize -> 500, AspectRatio -> 1/2, PlotLegends -> TextString@Row@{"T=", t}] , {t, 2 Pi, Pi, -.1} ]; Anim = Join[Anim1, Anim2]; 

enter image description here

UPDATE 2

If you want to do this with the manipulation box just add a two-dimensional picture size to your plot like this:

man = Manipulate[ Plot[Sin[x], {x, 0, end}, ImageSize -> {500, 250}], {end, Pi, 2 Pi, 0.1, Appearance -> "Open"}, ContentSize -> 550] 

enter image description here

Or this one (without fixing the plot range):

man = Manipulate[ Plot[Sin[x], {x, 0, end}, ImageSize -> {500, 250}], {end, Pi, 2 Pi, 0.1, Appearance -> "Open"}, ContentSize -> 550] 

enter image description here

$\endgroup$
5
  • $\begingroup$ I think you can still use manipulate and get good results if you use the fixed formatting there $\endgroup$ Commented Aug 11, 2016 at 15:02
  • $\begingroup$ Thank you for your help ... this I did already, but I wanted to see the whole window of the Manipulate function - therefore my question. $\endgroup$ Commented Aug 11, 2016 at 15:34
  • $\begingroup$ would it be possible to get a complete example, with the exporting, the inclusion of the manipulate UI, and the alternating between forwards and backwards? I'm not super Mathematica savvy yet so it's taking me a while to figure out how to string to it together. basically my whole interest in Mathematica is being able to type in 3-D equations and get exactly this behavior $\endgroup$ Commented Jan 13, 2019 at 19:51
  • $\begingroup$ @JosephGarvin can you give an example of the 3D equation that you're interested in? $\endgroup$ Commented Feb 14, 2019 at 16:04
  • $\begingroup$ @SiavJosep: something like $z=\frac{ax}{ax+by}$ with sliders for $a$ and $b$. $\endgroup$ Commented Feb 20, 2019 at 5:07
3
$\begingroup$

Another solution:

ManToGif[man_, name_String, step_Integer] := Export[name <> ".gif", Import[Export[FileNameJoin[{NotebookDirectory[], "test.avi"}], man], "ImageList"][[1 ;; -1 ;; step]]]; man2 = Manipulate[Plot[Sin[x], {x, 0, end}, PlotRange -> {{0, 2 Pi}, {-1, 1}}] , {end, 0, 2 Pi, 0.1}]; ManToGif[man2, FileNameJoin[{NotebookDirectory[], "test"}], 1]; 

This creates an AVI and corresponding GIF animation:

enter image description here

$\endgroup$
1
  • $\begingroup$ For the original ManToGif, see this answer by Vitaly and its link to his community post. (The original is essentially the same as this, but with a fix for MacOS.) $\endgroup$ Commented Mar 15, 2017 at 11:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.