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

Skip to content

Commit baea572

Browse files
committed
Update handles when canvas is resized
1 parent d2d2ce1 commit baea572

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/matplotlib/widgets.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,9 @@ def __init__(self, ax, onselect, drawtype='box',
29522952
# so the selector is defined in display coordinates, which makes
29532953
# it much easier to handle rotation and scaling
29542954
to_draw.set_transform(None)
2955+
# Becasue the transform in display coords, need to manually
2956+
# add a resize callback for when the axes are reszied
2957+
self.ax.figure.canvas.mpl_connect('resize_event', self._on_resize)
29552958

29562959
if drawtype == 'line':
29572960
_api.warn_deprecated(
@@ -3018,6 +3021,10 @@ def __init__(self, ax, onselect, drawtype='box',
30183021
property(lambda self: self.grab_range,
30193022
lambda self, value: setattr(self, "grab_range", value)))
30203023

3024+
def _on_resize(self, event):
3025+
# Callback for an Axes resize
3026+
self._update_handles()
3027+
30213028
@property
30223029
def _position_state(self):
30233030
"""Return a named tuple containing all position state attributes."""
@@ -3437,13 +3444,15 @@ def _update_selection_artist(self):
34373444
self._selection_artist.set_data([xy0[0], xy1[0]], [xy0[1], xy1[1]])
34383445

34393446
if self._interactive:
3440-
# Update displayed handles
3441-
self._corner_handles.set_data(*self.corners)
3442-
self._edge_handles.set_data(*self.edge_centers)
3443-
self._center_handle.set_data(*self.center)
3447+
self._update_handles()
34443448

34453449
self.update()
34463450

3451+
def _update_handles(self):
3452+
self._corner_handles.set_data(*self.corners)
3453+
self._edge_handles.set_data(*self.edge_centers)
3454+
self._center_handle.set_data(*self.center)
3455+
34473456
def _set_active_handle(self, event):
34483457
"""Set active handle based on the location of the mouse event."""
34493458
# Note: event.xdata/ydata in data coordinates, event.x/y in pixels

0 commit comments

Comments
 (0)