Skip to content

Commit ec0d33d

Browse files
committed
Merge pull request matplotlib#658 from agardelein/master
RectangleSelector: Handle case when button is still pressed when mouse is not in the axis
2 parents 1cd07a6 + 4e80240 commit ec0d33d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/matplotlib/widgets.py

+15
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,21 @@ def ignore(self, event):
12421242
if self.eventpress == None:
12431243
return event.inaxes!= self.ax
12441244

1245+
# If a button was pressed, check if the release-button is the
1246+
# same. If event is out of axis, limit the data coordinates to axes
1247+
# boundaries.
1248+
if event.button == self.eventpress.button and event.inaxes != self.ax:
1249+
(xdata, ydata) = self.ax.transData.inverted().transform_point((event.x, event.y))
1250+
x0, x1 = self.ax.get_xbound()
1251+
y0, y1 = self.ax.get_ybound()
1252+
xdata = max(x0, xdata)
1253+
xdata = min(x1, xdata)
1254+
ydata = max(y0, ydata)
1255+
ydata = min(y1, ydata)
1256+
event.xdata = xdata
1257+
event.ydata = ydata
1258+
return False
1259+
12451260
# If a button was pressed, check if the release-button is the
12461261
# same.
12471262
return (event.inaxes!=self.ax or

0 commit comments

Comments
 (0)