[IPython-User] proper animation in notebook?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[IPython-User] proper animation in notebook?

Brian Blais-2
Hello,

I have just found out how to do animations within an ipython notebook,
by looking at:
http://nbviewer.ipython.org/github/ipython/ipython/blob/2.x/examples/Notebook/Animations%20Using%20clear_output.ipynb

However, when I do it myself I get the animation, but I get a memory
leak - the memory of the python process just keeps growing.  Here's my
code:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

import sys
import time
from IPython.display import display, clear_output

x=linspace(0,6,100)
for t in linspace(0,20,100):
    clear_output(wait=True)
    f=figure(figsize=(10,10))
    plot(sin(x)*sin(t),'-o')
    gca().set_ylim([-1,1])
    display(f)
    close()


somehow I think it isn't actually deleting the figures from one call
to another, so it is building up in the background, although I am not
sure.  Is there a proper way to do this kind of animation in the
notebook without the memory continually increasing?

thanks!

Brian Blais

-----------------

             [hidden email]
             http://web.bryant.edu/~bblais
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: proper animation in notebook?

Steve Holden-5
Hi,

Your code as shown is incorrect because it doesn't import many of the symbols it uses.

I found the following code appeared to work without any issues:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

import sys
import time
from IPython.display import display, clear_output

x=np.linspace(0,6,100)
for t in np.linspace(0,20,100):
   clear_output(wait=True)
   f=plt.figure(figsize=(10,10))
   plt.plot(np.sin(x)*np.sin(t),'-o')
   plt.gca().set_ylim([-1,1])
   display(f)
   plt.close()

Further queries should be sent to the python-dev list, as this one is being phased out.

regards
 Steve

On Oct 11, 2014, at 12:18 AM, Brian Blais <[hidden email]> wrote:

However, when I do it myself I get the animation, but I get a memory
leak - the memory of the python process just keeps growing.  Here's my
code:

-- 
Steve Holden [hidden email] +1 571 484 6266 @holdenweb




_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user

smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: proper animation in notebook?

Brian Blais-2
On Sat, Oct 11, 2014 at 4:07 AM, Steve Holden <[hidden email]> wrote:

> I found the following code appeared to work without any issues:
>
> %matplotlib inline
> import numpy as np
> import matplotlib.pyplot as plt
>
> import sys
> import time
> from IPython.display import display, clear_output
>
> x=np.linspace(0,6,100)
> for t in np.linspace(0,20,100):
>    clear_output(wait=True)
>    f=plt.figure(figsize=(10,10))
>    plt.plot(np.sin(x)*np.sin(t),'-o')
>    plt.gca().set_ylim([-1,1])
>    display(f)
>    plt.close()
>
> Further queries should be sent to the python-dev list, as this one is being
> phased out.
>

Running this code makes a working animation, but watching the memory
usage of the python2.7 process it is clear there is a memory leak - it
starts around 150 M and climbs to 300 M.  Running for longer keeps
this going.  I think the figures are being generated, cleared in the
notebook, but still existing somehow in the background.  Is there a
way to determine if this is happening?  Is there a proper way to write
the animation to avoid this?

thanks!

Brian Blais

-----------------

             [hidden email]
             http://web.bryant.edu/~bblais
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user
Reply | Threaded
Open this post in threaded view
|

Re: proper animation in notebook?

Paul Moore
In reply to this post by Steve Holden-5
On 11 October 2014 09:07, Steve Holden <[hidden email]> wrote:
> Further queries should be sent to the python-dev list, as this one is being
> phased out.

That should have been ipython-dev, not python-dev :-)
Paul
_______________________________________________
IPython-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/ipython-user