Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12d800d

Browse files
committed
Fix legend dragging.
Without this PR, after ``` plot([1, 2], label="foo"); legend().set_draggable(True) ``` when dragging the legend, releasing the mouse button results in ``` Traceback (most recent call last): File ".../matplotlib/cbook/__init__.py", line 236, in process func(*args, **kwargs) File ".../matplotlib/offsetbox.py", line 1716, in on_release self.finalize_offset() File ".../matplotlib/legend.py", line 78, in finalize_offset {"loc": self._update_loc, "bbox": self._bbox_to_anchor}, AttributeError: 'DraggableLegend' object has no attribute '_bbox_to_anchor' ``` See comment in code for more explanations. A test may be nice but tricky to write...
1 parent f4c25b2 commit 12d800d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/matplotlib/legend.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def artist_picker(self, legend, evt):
7474
return self.legend.contains(evt)
7575

7676
def finalize_offset(self):
77-
update_method = cbook._check_getitem(
78-
{"loc": self._update_loc, "bbox": self._bbox_to_anchor},
79-
update=self._update)
80-
update_method(self.get_loc_in_canvas())
77+
if self._update == "loc":
78+
self._update_loc(self.get_loc_in_canvas())
79+
elif self._update == "bbox":
80+
self._bbox_to_anchor(self.get_loc_in_canvas())
8181

8282
def _update_loc(self, loc_in_canvas):
8383
bbox = self.legend.get_bbox_to_anchor()

0 commit comments

Comments
 (0)