legend breaks clf()

Hi,

I just downloaded and installed the latest matplotlib (0.90.1) and the following problem occurred:

plot([0,1])

scatter([0.5], [0.5])

Should be one Line2D

print gca().lines

Should be one RegularPolyCollection

print gca().collections

Now load a legend:

legend()

Should be one Line2D !!! BUT NOW THERE IS A RegularPolyCollection !!!

print gca().lines

Should be one RegularPolyCollection

print gca().collections

Clearing throws the exception cuz it is trying to call

line methods (get_xdata) on a poly-collection

clf()

To fix this problem, I edited my axes.py file. In the legend() function, there is a get_handles() function which does the following (in psuedo code):

handles = self.lines

handles.extend(self.patches)

handles.extend( — collections —)

This is actually modifying the self.lines object. If instead I import the copy module and do:

handles = copy.copy(self.lines)

then everything behaves better. I haven’t done extensive testing to see if this breaks anything else though. Is there some place to enter bugs or is posting to this mailing list good enough?

Cheers,

Jessica

Thanks for the hint. I just fixed the problem in SVN.

No idea how this problem would have popped up recently. I did some
changes in legend just before 0.90.1, but I do not see how these would
have caused the problem to show up. From what I see, the flaw should
have been there all along. Well, whatever ... it is fixed now.

Jessica Lu wrote:

···

Hi,

I just downloaded and installed the latest matplotlib (0.90.1) and the
following problem occurred:

>>>
plot([0,1])
scatter([0.5], [0.5])

# Should be one Line2D
print gca().lines
# Should be one RegularPolyCollection
print gca().collections

# Now load a legend:
legend()

# Should be one Line2D !!! BUT NOW THERE IS A RegularPolyCollection !!!
print gca().lines
# Should be one RegularPolyCollection
print gca().collections

# Clearing throws the exception cuz it is trying to call
# line methods (get_xdata) on a poly-collection
clf()
>>>

To fix this problem, I edited my axes.py file. In the legend()
function, there is a get_handles() function which does the following
(in psuedo code):

handles = self.lines
handles.extend(self.patches)
handles.extend( --- collections ---)

This is actually modifying the self.lines object. If instead I import
the copy module and do:

handles = copy.copy(self.lines)

then everything behaves better. I haven't done extensive testing to
see if this breaks anything else though. Is there some place to enter
bugs or is posting to this mailing list good enough?

Cheers,
Jessica
------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options