On Thu, Feb 2, 2012 at 6:25 PM, Jerzy Karczmarczuk <
jerzy.karczmarc...@unicaen.fr> wrote:

>  Benjamin Root on my suggestion that one can use del instead of remove :
>
>  There are methods for ax that properly handle removal of types of artists
> that have been attached to an axes.  The above approach assumes that no
> other collections have been plotted that you wanted to keep.  The approach
> I gave is a very surgical method that makes sure that only what is supposed
> to be removed gets removed.  Both are valid, and their usefulness depends
> upon which view of the data you need (remove types of artists versus
> removing particular artists).
>
>  Yes, absolutely.
> With just a little remark: remove is a Python function which *searches*
> the list for a given value. del uses indices, so
> del lst[10000]
> will be most probably faster than lst.remove(value), if this value happens
> to occur for the first time at index 10000. Unless Matplotlib uses a
> specially tuned version of remove.
>
>
Don't confuse Python's remove() method for lists with the remove() method
for matplotlib Artist (and subclassed Artists) objects.  Collections are a
subclass of Artist, and remove() simply means "remove me from the Axes
object I was connected to".  This is because an Axes object contains lists
to the artists, collections and others that have been attached to it, and
each Artist has a reference to the Axes object that it was connected to.
So, calling remove() on an Artist will do all the appropriate house-keeping.

matplotlib Artist objects do not implement __del__(), so deleting an Artist
before calling remove() will not properly disconnect all of the callbacks
and references.  I suspect that the only reason why this works at all is
that there is a lot of usage of weakrefs and it so there might be enough
error-checking to keep everything from crashing.

Others who are much more familiar with the underlying architecture may be
able to comment better.  In the meantime, the pedantic, better form of:

del ax.collections[:]

would be:

for item in ax.collections :
    item.remove()
del ax.collections[:]




>
>
>> Under Windows XP, ion() is not too
>> compatible with show().
>> TKAgg (by default), WXAgg and GTKAgg bomb Bens program (and without
>> draw() nothing is plotted).
>>
>>
> That would be a bug and should be reported (assuming that it is in the
> latest version).  Make sure that you are using at least v1.0.1 (preferably
> v1.1.0) to make sure that show() should do what you want.  Any version
> earlier than v1.0.1 is very unpredictable with respect to multiple show()
> calls.
>
> I use 1.1.0. (Python 2.7.2) I didn't report any bug because I didn't know
> whether this was a bug...
>

Then, please do report it.


>  But there are more...
> The animation module uses various timers depending on the back-end. This
> is -- perhaps -- the result of the fact that Python standard Timer (a
> subclass of Thread) is, to say it mildly, rather weak. So, under Tk the
> system uses after(), wx offers its timers, etc. Timed animation works
> differently under various backends.
>

This should also be a new thread, and possibly a new bug report as well.

Ben Root
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to