[IPython-dev] proper animation in notebook?

Brian Blais bblais at gmail.com
Mon Oct 13 19:58:48 EDT 2014

On Sat, Oct 11, 2014 at 4:07 AM, Steve Holden <steve at holdenweb.com> 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 ipython-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?


Brian Blais

             bblais at gmail.com

More information about the IPython-dev mailing list