Skip to content

Commit 2938c6f

Browse files
authored
Merge pull request #15855 from anntzer/3dcb
Simplify 3d axes callback setup.
2 parents 5407256 + 4e023d6 commit 2938c6f

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def __init__(
7979

8080
if rect is None:
8181
rect = [0.0, 0.0, 1.0, 1.0]
82-
self._cids = []
8382

8483
self.initial_azim = azim
8584
self.initial_elev = elev
@@ -115,6 +114,12 @@ def __init__(
115114
self._zcid = None
116115

117116
self.mouse_init()
117+
self.figure.canvas.mpl_connect(
118+
'motion_notify_event', self._on_move),
119+
self.figure.canvas.mpl_connect(
120+
'button_press_event', self._button_press),
121+
self.figure.canvas.mpl_connect(
122+
'button_release_event', self._button_release),
118123
self.set_top_view()
119124

120125
self.patch.set_linewidth(0)
@@ -1004,8 +1009,7 @@ def get_proj(self):
10041009

10051010
def mouse_init(self, rotate_btn=1, zoom_btn=3):
10061011
"""
1007-
Initializes mouse button callbacks to enable 3D rotation of the axes.
1008-
Also optionally sets the mouse buttons for 3D rotation and zooming.
1012+
Set the mouse buttons for 3D rotation and zooming.
10091013
10101014
Parameters
10111015
----------
@@ -1015,20 +1019,16 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3):
10151019
The mouse button or buttons to use to zoom the 3D axes.
10161020
"""
10171021
self.button_pressed = None
1018-
self._cids = [
1019-
self.figure.canvas.mpl_connect(
1020-
'motion_notify_event', self._on_move),
1021-
self.figure.canvas.mpl_connect(
1022-
'button_press_event', self._button_press),
1023-
self.figure.canvas.mpl_connect(
1024-
'button_release_event', self._button_release),
1025-
]
10261022
# coerce scalars into array-like, then convert into
10271023
# a regular list to avoid comparisons against None
10281024
# which breaks in recent versions of numpy.
10291025
self._rotate_btn = np.atleast_1d(rotate_btn).tolist()
10301026
self._zoom_btn = np.atleast_1d(zoom_btn).tolist()
10311027

1028+
def disable_mouse_rotation(self):
1029+
"""Disable mouse buttons for 3D rotation and zooming."""
1030+
self.mouse_init(rotate_btn=[], zoom_btn=[])
1031+
10321032
def can_zoom(self):
10331033
"""
10341034
Return *True* if this axes supports the zoom box button functionality.
@@ -1069,13 +1069,6 @@ def cla(self):
10691069

10701070
self.grid(rcParams['axes3d.grid'])
10711071

1072-
def disable_mouse_rotation(self):
1073-
"""Disable mouse button callbacks."""
1074-
# Disconnect the various events we set.
1075-
for cid in self._cids:
1076-
self.figure.canvas.mpl_disconnect(cid)
1077-
self._cids = []
1078-
10791072
def _button_press(self, event):
10801073
if event.inaxes == self:
10811074
self.button_pressed = event.button

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy