From fcd9fd899f1bff24ba0a5f7c523594c030345ed2 Mon Sep 17 00:00:00 2001 From: Ben Root Date: Thu, 14 Jul 2011 11:12:51 -0500 Subject: [PATCH 1/4] Added a "can_pan()" function and included it in the generic panning logic. Also added the function to the geo, polar, and mplot3d axes with the appropriate return values. This closes issue #110. --- lib/matplotlib/axes.py | 6 ++++++ lib/matplotlib/backend_bases.py | 3 ++- lib/matplotlib/projections/geo.py | 6 ++++++ lib/matplotlib/projections/polar.py | 6 ++++++ lib/mpl_toolkits/mplot3d/axes3d.py | 3 +++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index c6dd94a9c47e..f192e2471022 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -2781,6 +2781,12 @@ def can_zoom(self): """ return True + def can_pan(self) : + """ + Return *True* if this axes support the pan action + """ + return True + def get_navigate(self): """ Get whether the axes responds to navigation commands diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index aedb15abe2b4..620f24e006cd 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2512,7 +2512,8 @@ def press_pan(self, event): self._xypress=[] for i, a in enumerate(self.canvas.figure.get_axes()): - if x is not None and y is not None and a.in_axes(event) and a.get_navigate(): + if x is not None and y is not None and a.in_axes(event) \ + and a.get_navigate() and a.can_pan() : a.start_pan(x, y, event.button) self._xypress.append((a, i)) self.canvas.mpl_disconnect(self._idDrag) diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index 84a21c947060..37933dcd2caf 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -222,6 +222,12 @@ def can_zoom(self): """ return False + def can_pan(self) : + """ + Return True if this axes support the pan action + """ + return False + def start_pan(self, x, y, button): pass diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index c4589040574a..6a6902a72c39 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -576,6 +576,12 @@ def can_zoom(self): """ return False + def can_pan(self) : + """ + Return True if this axes support the pan action + """ + return True + def start_pan(self, x, y, button): angle = self._r_label1_position.to_values()[4] / 180.0 * np.pi mode = '' diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 267beb9f9f24..9045e2974b35 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -808,6 +808,9 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3): def can_zoom(self) : return False + def can_pan(self) : + return False + def cla(self): """Clear axes and disable mouse button callbacks. """ From 7a540d4c9a999f2b7b283c531a54325b8bdbf847 Mon Sep 17 00:00:00 2001 From: Ben Root Date: Wed, 3 Aug 2011 15:08:46 -0500 Subject: [PATCH 2/4] Updated the docs with respect to can_zoom() and can_pan(). --- lib/matplotlib/axes.py | 4 ++-- lib/matplotlib/projections/polar.py | 10 ++++++++-- lib/mpl_toolkits/mplot3d/axes3d.py | 10 ++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index f192e2471022..bfac1369c4ef 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -2777,13 +2777,13 @@ def format_coord(self, x, y): def can_zoom(self): """ - Return *True* if this axes support the zoom box + Return *True* if this axes support the zoom box button functionality. """ return True def can_pan(self) : """ - Return *True* if this axes support the pan action + Return *True* if this axes supports any pan/zoom button functionality. """ return True diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index 6a6902a72c39..ec5526cddcb1 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -572,13 +572,19 @@ def get_data_ratio(self): def can_zoom(self): """ - Return True if this axes support the zoom box + Return *True* if this axes supports the zoom box button functionality. + + Polar axes do not support zoom boxes. """ return False def can_pan(self) : """ - Return True if this axes support the pan action + Return *True* if this axes supports the pan/zoom button functionality. + + For polar axes, this is slightly misleading. Both panning and + zooming are performed by the same button. Panning is performed + in azimuth while zooming is done along the radial. """ return True diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 9045e2974b35..65be58e1dd16 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -806,9 +806,19 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3): self._zoom_btn = np.atleast_1d(zoom_btn) def can_zoom(self) : + """ + Return *True* if this axes supports the zoom box button functionality. + + 3D axes objects do not use the zoom box button. + """ return False def can_pan(self) : + """ + Return *True* if this axes supports the pan/zoom button functionality. + + 3D axes objects do not use the pan/zoom button. + """ return False def cla(self): From 261cb76bf27f418bd9c9fad64eebb5548f69f39c Mon Sep 17 00:00:00 2001 From: Ben Root Date: Wed, 3 Aug 2011 19:01:48 -0500 Subject: [PATCH 3/4] Made similar doc changes in geo.py. Also some code style fixes. --- lib/matplotlib/backend_bases.py | 14 ++++++++------ lib/matplotlib/projections/geo.py | 8 ++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 620f24e006cd..4d7bcd43a35b 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2512,12 +2512,13 @@ def press_pan(self, event): self._xypress=[] for i, a in enumerate(self.canvas.figure.get_axes()): - if x is not None and y is not None and a.in_axes(event) \ - and a.get_navigate() and a.can_pan() : + if (x is not None and y is not None and a.in_axes(event) and + a.get_navigate() and a.can_pan()) : a.start_pan(x, y, event.button) self._xypress.append((a, i)) self.canvas.mpl_disconnect(self._idDrag) - self._idDrag=self.canvas.mpl_connect('motion_notify_event', self.drag_pan) + self._idDrag=self.canvas.mpl_connect('motion_notify_event', + self.drag_pan) self.press(event) @@ -2538,9 +2539,10 @@ def press_zoom(self, event): self._xypress=[] for i, a in enumerate(self.canvas.figure.get_axes()): - if x is not None and y is not None and a.in_axes(event) \ - and a.get_navigate() and a.can_zoom(): - self._xypress.append(( x, y, a, i, a.viewLim.frozen(), a.transData.frozen())) + if (x is not None and y is not None and a.in_axes(event) and + a.get_navigate() and a.can_zoom()) : + self._xypress.append(( x, y, a, i, a.viewLim.frozen(), + a.transData.frozen() )) id1 = self.canvas.mpl_connect('motion_notify_event', self.drag_zoom) diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index 37933dcd2caf..8a20f5c2768d 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -218,13 +218,17 @@ def get_data_ratio(self): def can_zoom(self): """ - Return True if this axes support the zoom box + Return *True* if this axes supports the zoom box button functionality. + + This axes object does not support interactive zoom box. """ return False def can_pan(self) : """ - Return True if this axes support the pan action + Return *True* if this axes supports the pan/zoom button functionality. + + This axes object does not support interactive pan/zoom. """ return False From aa0f04e1faf584328e6f301a0d3e5a87ee7027fd Mon Sep 17 00:00:00 2001 From: Ben Root Date: Wed, 3 Aug 2011 19:45:35 -0500 Subject: [PATCH 4/4] Fixed a minor typo I made in one of the can_pan docs. --- lib/matplotlib/axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index bfac1369c4ef..81d043f6d7a5 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -2777,7 +2777,7 @@ def format_coord(self, x, y): def can_zoom(self): """ - Return *True* if this axes support the zoom box button functionality. + Return *True* if this axes supports the zoom box button functionality. """ return True