From f871591c1c8feed0fbe3ad04dc37b2771b028d1c Mon Sep 17 00:00:00 2001 From: Arnaud Gardelein Date: Thu, 5 Jan 2012 21:49:59 +0100 Subject: [PATCH 1/2] Handle events in RectangleSelector when mouse is out of axis and button still pressed --- lib/matplotlib/widgets.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 8202e6be4677..d002231177b0 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -1242,6 +1242,21 @@ def ignore(self, event): if self.eventpress == None: return event.inaxes!= self.ax + # If a button was pressed, check if the release-button is the + # same. If event is out of axis, limit the data coordinates to axes + # boundaries. + if event.button == self.eventpress.button and event.inaxes != self.ax: + (xdata, ydata) = self.ax.transData.inverted().transform_point((event.x, event.y)) + xlim = self.ax.get_xlim() + ylim = self.ax.get_ylim() + if xdata < xlim[0]: xdata = xlim[0] + if xdata > xlim[1]: xdata = xlim[1] + if ydata < ylim[0]: ydata = ylim[0] + if ydata > ylim[1]: ydata = ylim[1] + event.xdata = xdata + event.ydata = ydata + return False + # If a button was pressed, check if the release-button is the # same. return (event.inaxes!=self.ax or From 4e8024085d1f7eb693cc9cccd453c42ec2ed5f50 Mon Sep 17 00:00:00 2001 From: Arnaud Gardelein Date: Sun, 8 Jan 2012 16:11:03 +0100 Subject: [PATCH 2/2] Save deferencing operations, use get_[x|y]bound() As per Eric Firing comment --- lib/matplotlib/widgets.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index d002231177b0..ebb0ceab45ba 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -1247,12 +1247,12 @@ def ignore(self, event): # boundaries. if event.button == self.eventpress.button and event.inaxes != self.ax: (xdata, ydata) = self.ax.transData.inverted().transform_point((event.x, event.y)) - xlim = self.ax.get_xlim() - ylim = self.ax.get_ylim() - if xdata < xlim[0]: xdata = xlim[0] - if xdata > xlim[1]: xdata = xlim[1] - if ydata < ylim[0]: ydata = ylim[0] - if ydata > ylim[1]: ydata = ylim[1] + x0, x1 = self.ax.get_xbound() + y0, y1 = self.ax.get_ybound() + xdata = max(x0, xdata) + xdata = min(x1, xdata) + ydata = max(y0, ydata) + ydata = min(y1, ydata) event.xdata = xdata event.ydata = ydata return False