Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

EDIT:

"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?


EDIT2:

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)

share|improve this question
1  
Can you provide the plot, or someting equivalent? – Yves Klett Jan 4 at 9:50
1  
If rendering of your Plot takes too much time, consider Rasterizeing it. – Yves Klett Jan 4 at 10:30
@YvesKlett, if you Rasterize it, then when combined with Show, the second plot will not appear. If you try p = Rasterize[Plot[Sin[x], {x, -Pi, Pi}]]; Animate[Show[p, Plot[Cos[a x], {x, -Pi, Pi}]], {a, .1, 1, .1}] and compare to this: p = Plot[Sin[x], {x, -Pi, Pi}]; Animate[Show[p, Plot[Cos[a x], {x, -Pi, Pi}]], {a, .1, 1, .1}] you'll see this effect. – Nasser Jan 4 at 10:41
I think this is due to Rasterize use the pixel coordinate system of the image, while un-rasterized uses its own system. – J. C. Leitão Jan 4 at 11:02
@J.C.Leitão true - perhaps someone can help out here with a nifty solution. O – Yves Klett Jan 4 at 11:11

1 Answer

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}]
share|improve this answer
"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. – J. C. Leitão Jan 4 at 9:46
I've added some information on the question to clarify your point. – J. C. Leitão Jan 4 at 9:49
I am a little confused. Rendering means painting the pixels on the screen from the data. This has to be done each time the animation moves. The only difference when you make the plot on the side, is that the computation needed to generate the data for the plot is done once. Yes, the plot will be rendered on the screen each time from the data. I do not know how can one avoid this if you wish to have it part of a moving animation without access to the internal graphics screen buffer and such. Any way, I am no expert on this by any means, so there might be a way to do it. – Nasser Jan 4 at 10:18
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). – J. C. Leitão Jan 4 at 10:21
I did try the example. It took long time to make the plot. But when I run the animation, it ran much faster. The time needed was only for rendering the expensive plot, not making it. btw, M is slow in rendering any way. I complained about this many times before. When there is lots of data to render (complex plot, many plots), it slows down. I asked about this before at Mathgroup and here. I see this problem all the time when I make demos. simulation becomes slow when I have lots of plots to display.... – Nasser Jan 4 at 10:31
show 1 more 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.