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

Skip to content

Commit 430788e

Browse files
committed
Merge pull request #399 from WeatherGod/add_can_pan
Added a "can_pan()" function and included it in the generic panning logic
2 parents 45870f2 + aa0f04e commit 430788e

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

lib/matplotlib/axes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2778,7 +2778,13 @@ def format_coord(self, x, y):
27782778

27792779
def can_zoom(self):
27802780
"""
2781-
Return *True* if this axes support the zoom box
2781+
Return *True* if this axes supports the zoom box button functionality.
2782+
"""
2783+
return True
2784+
2785+
def can_pan(self) :
2786+
"""
2787+
Return *True* if this axes supports any pan/zoom button functionality.
27822788
"""
27832789
return True
27842790

lib/matplotlib/backend_bases.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,11 +2512,13 @@ def press_pan(self, event):
25122512

25132513
self._xypress=[]
25142514
for i, a in enumerate(self.canvas.figure.get_axes()):
2515-
if x is not None and y is not None and a.in_axes(event) and a.get_navigate():
2515+
if (x is not None and y is not None and a.in_axes(event) and
2516+
a.get_navigate() and a.can_pan()) :
25162517
a.start_pan(x, y, event.button)
25172518
self._xypress.append((a, i))
25182519
self.canvas.mpl_disconnect(self._idDrag)
2519-
self._idDrag=self.canvas.mpl_connect('motion_notify_event', self.drag_pan)
2520+
self._idDrag=self.canvas.mpl_connect('motion_notify_event',
2521+
self.drag_pan)
25202522

25212523
self.press(event)
25222524

@@ -2537,9 +2539,10 @@ def press_zoom(self, event):
25372539

25382540
self._xypress=[]
25392541
for i, a in enumerate(self.canvas.figure.get_axes()):
2540-
if x is not None and y is not None and a.in_axes(event) \
2541-
and a.get_navigate() and a.can_zoom():
2542-
self._xypress.append(( x, y, a, i, a.viewLim.frozen(), a.transData.frozen()))
2542+
if (x is not None and y is not None and a.in_axes(event) and
2543+
a.get_navigate() and a.can_zoom()) :
2544+
self._xypress.append(( x, y, a, i, a.viewLim.frozen(),
2545+
a.transData.frozen() ))
25432546

25442547
id1 = self.canvas.mpl_connect('motion_notify_event', self.drag_zoom)
25452548

lib/matplotlib/projections/geo.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,17 @@ def get_data_ratio(self):
218218

219219
def can_zoom(self):
220220
"""
221-
Return True if this axes support the zoom box
221+
Return *True* if this axes supports the zoom box button functionality.
222+
223+
This axes object does not support interactive zoom box.
224+
"""
225+
return False
226+
227+
def can_pan(self) :
228+
"""
229+
Return *True* if this axes supports the pan/zoom button functionality.
230+
231+
This axes object does not support interactive pan/zoom.
222232
"""
223233
return False
224234

lib/matplotlib/projections/polar.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,22 @@ def get_data_ratio(self):
572572

573573
def can_zoom(self):
574574
"""
575-
Return True if this axes support the zoom box
575+
Return *True* if this axes supports the zoom box button functionality.
576+
577+
Polar axes do not support zoom boxes.
576578
"""
577579
return False
578580

581+
def can_pan(self) :
582+
"""
583+
Return *True* if this axes supports the pan/zoom button functionality.
584+
585+
For polar axes, this is slightly misleading. Both panning and
586+
zooming are performed by the same button. Panning is performed
587+
in azimuth while zooming is done along the radial.
588+
"""
589+
return True
590+
579591
def start_pan(self, x, y, button):
580592
angle = self._r_label1_position.to_values()[4] / 180.0 * np.pi
581593
mode = ''

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,19 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3):
806806
self._zoom_btn = np.atleast_1d(zoom_btn)
807807

808808
def can_zoom(self) :
809+
"""
810+
Return *True* if this axes supports the zoom box button functionality.
811+
812+
3D axes objects do not use the zoom box button.
813+
"""
814+
return False
815+
816+
def can_pan(self) :
817+
"""
818+
Return *True* if this axes supports the pan/zoom button functionality.
819+
820+
3D axes objects do not use the pan/zoom button.
821+
"""
809822
return False
810823

811824
def cla(self):

0 commit comments

Comments
 (0)