Skip to content

Commit f871591

Browse files
agardeleinArnaud Gardelein
authored and
Arnaud Gardelein
committed
Handle events in RectangleSelector when mouse is out of axis and button still pressed
1 parent beb4821 commit f871591

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+
xlim = self.ax.get_xlim()
1251+
ylim = self.ax.get_ylim()
1252+
if xdata < xlim[0]: xdata = xlim[0]
1253+
if xdata > xlim[1]: xdata = xlim[1]
1254+
if ydata < ylim[0]: ydata = ylim[0]
1255+
if ydata > ylim[1]: ydata = ylim[1]
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)