I have a plot which is rather expensive to "present", and I want to create an animation on top of it.


"present" here does not just mean create the plot, but also to rasterize and present in on the Notebook.

I tried to create the plot before by doing plot=Plot[...] and then use Show[plot,Animate[...]], but Mathematica does not allow to combine plots with Animations. If I put the plot inside the animation, it gets really slow as it re-renders the plot at each frame.

Another thing I tried was to present the plot as an background image of the animation, but I'm not being able to make backgrounds other than RGBColors (and I don't even know if this works).

Is there any proper way of achieving this?


One example of such plot

plot = ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}, 
PlotPoints -> 200, MaxRecursion -> 2, Mesh -> None];

The number of PlotPoints is big because in my particular case the function to be plotted is non trivial, and requires a lot of resolution to see anything. (I'm not putting here the code because the function is obtained as an iterative process, and is out of the scope of this question)

  • 1
    $\begingroup$ Can you provide the plot, or someting equivalent? $\endgroup$ – Yves Klett Jan 4 '13 at 9:50
  • 1
    $\begingroup$ If rendering of your Plot takes too much time, consider Rasterizeing it. $\endgroup$ – Yves Klett Jan 4 '13 at 10:30
  • $\begingroup$ I think this is due to Rasterize use the pixel coordinate system of the image, while un-rasterized uses its own system. $\endgroup$ – Jorge Leitao Jan 4 '13 at 11:02
  • $\begingroup$ @J.C.Leitão true - perhaps someone can help out here with a nifty solution. O $\endgroup$ – Yves Klett Jan 4 '13 at 11:11

Can't you make the Plot on the side first, then add it later? Since it is already made then no extra cost.

p = Plot[Sin[x], {x, -Pi, Pi}];  (*make the expensive plot *)
Animate[Show[p, Plot[Cos[a x], {x, -Pi, Pi}]], {a, .1, 1, .1}]
| improve this answer | |
  • $\begingroup$ "It is expensive to "present"": it is expensive to mathematica rasterize it to show on the notebook. When Mathematica animates, it apparently re-rasterizes all inside the Animate[] function. I want to have an animation on top of a 1-time rendered plot. $\endgroup$ – Jorge Leitao Jan 4 '13 at 9:46
  • $\begingroup$ I've added some information on the question to clarify your point. $\endgroup$ – Jorge Leitao Jan 4 '13 at 9:49
  • $\begingroup$ Maybe not rendering, more like rastering: at some point mathematica has to transform its data on a data able to be plotted. This is an expensive operation: try the example I added on the question (by e.g. changing the number of PlotPoint's). $\endgroup$ – Jorge Leitao Jan 4 '13 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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