[Matplotlib-users] animation with FuncAnimation (mpl 3.0.2)

Alan Isaac alan.isaac at gmail.com
Fri Mar 22 16:08:38 EDT 2019


On 3/22/2019 3:41 PM, Eric Firing wrote:
> It's not a bug--it's intentional and documented--but I agree it is not what one might expect. 

Oh I see, it is documented under `init_func`.  Thanks!
Perhaps it shd also be documented under `func`.  (That wd have helped me.)


> This is a basic aspect of the Python language: when the last reference to an object is removed, the object goes away.  Assigning a name to the FuncAnimation instance keeps it alive so that it can do its work when the blocking "plt.show()" is called.


This approach seems to depend sensitively on the timing of garbage collection.
Is it part of the Python specification that a variable created in a scope
will ensure the object's existence until the scope is exited, even if the
variable is unused?  Is that guaranteed to work regardless of the Python
implementation? (I searched but did not find an answer to this question.)

And it still seems like magic to me: how is matplotlib finding the object?
For example, if mpl registered the object upon creation, it seems like the
assignment would not matter.  But the assignment does matter,
so some other approach is used.

Thanks!
Alan


More information about the Matplotlib-users mailing list