Bug in Draggable Legend

Hi all,

I found a small bug in the Draggable Legend feature when you single-click on a
legend, but don't drag it. It raises a TypeError.

Here's code to reproduce. Try dragging the legend, then single-click the
legend.

#!/usr/bin/env python
import matplotlib as mpl
import pylab

fig = pylab.figure()
ax = fig.add_subplot(111)
ax.plot(range(10), range(10), c='r', marker='^', picker=5, label='Ramp')
legn = ax.legend()
legn.draggable()
pylab.show()

Here's the stacktrace when I single-click:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
    return self.func(*args)
  File "C:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py",
line 312, in button_release_event
    FigureCanvasBase.button_release_event(self, x, y, num, guiEvent=event)
  File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line 1561,
in button_release_event
    self.callbacks.process(s, event)
  File "C:\Python26\lib\site-packages\matplotlib\cbook.py", line 262, in process
    proxy(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\cbook.py", line 188, in
__call__
    return mtd(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\offsetbox.py", line 1466, in
on_release
    self.finalize_offset()
  File "C:\Python26\lib\site-packages\matplotlib\legend.py", line 51, in
finalize_offset
    loc_in_canvas = self.get_loc_in_canvas()
  File "C:\Python26\lib\site-packages\matplotlib\offsetbox.py", line 1512, in
get_loc_in_canvas
    ox, oy = offsetbox._offset
TypeError: 'instancemethod' object is not iterable

Jim

I just committed a change that I believe that fixes this problem.

Regards,

-JJ

···

On Fri, Mar 4, 2011 at 12:58 AM, James Kitchen <jim22k@...42...> wrote:

Hi all,

I found a small bug in the Draggable Legend feature when you single-click on a
legend, but don't drag it. It raises a TypeError.

Here's code to reproduce. Try dragging the legend, then single-click the
legend.

#!/usr/bin/env python
import matplotlib as mpl
import pylab

fig = pylab.figure()
ax = fig.add_subplot(111)
ax.plot(range(10), range(10), c='r', marker='^', picker=5, label='Ramp')
legn = ax.legend()
legn.draggable()
pylab.show()

Here's the stacktrace when I single-click:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python26\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Python26\lib\site-packages\matplotlib\backends\backend_tkagg.py",
line 312, in button_release_event
FigureCanvasBase.button_release_event(self, x, y, num, guiEvent=event)
File "C:\Python26\lib\site-packages\matplotlib\backend_bases.py", line 1561,
in button_release_event
self.callbacks.process(s, event)
File "C:\Python26\lib\site-packages\matplotlib\cbook.py", line 262, in process
proxy(*args, **kwargs)
File "C:\Python26\lib\site-packages\matplotlib\cbook.py", line 188, in
__call__
return mtd(*args, **kwargs)
File "C:\Python26\lib\site-packages\matplotlib\offsetbox.py", line 1466, in
on_release
self.finalize_offset()
File "C:\Python26\lib\site-packages\matplotlib\legend.py", line 51, in
finalize_offset
loc_in_canvas = self.get_loc_in_canvas()
File "C:\Python26\lib\site-packages\matplotlib\offsetbox.py", line 1512, in
get_loc_in_canvas
ox, oy = offsetbox._offset
TypeError: 'instancemethod' object is not iterable

Jim

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options

Confirmed that it fixes the problem for me on the GTKAgg backend as well.

Ben Root

···

On Thu, Mar 3, 2011 at 10:30 AM, Jae-Joon Lee <lee.j.joon@…149…> wrote:

I just committed a change that I believe that fixes this problem.

https://github.com/matplotlib/matplotlib/commit/be420a34031c9c50813bc5be5f01a3cfb49639a1

Regards,

-JJ

Looks like that fixed it. Thanks!

Jim

···

From: Benjamin Root <ben.root@…553…>
To: Jae-Joon Lee <lee.j.joon@…149…>
Cc: James Kitchen <jim22k@…42…>; matplotlib-devel@lists.sourceforge.net
Sent: Thu, March 3, 2011 11:40:32 AM
Subject: Re: [matplotlib-devel] Bug in Draggable
Legend

On Thu, Mar 3, 2011 at 10:30 AM, Jae-Joon Lee <lee.j.joon@…149…> wrote:

I just committed a change that I believe that fixes this problem.

https://github.com/matplotlib/matplotlib/commit/be420a34031c9c50813bc5be5f01a3cfb49639a1

Regards,

-JJ

Confirmed that it fixes the problem for me on the GTKAgg backend as well.

Ben Root