Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit acbec0c

Browse filesBrowse files
Do not jump when zooming and mouse goes over other subplot
1 parent d7a3d6c commit acbec0c
Copy full SHA for acbec0c

File tree

Expand file treeCollapse file tree

1 file changed

+19
-19
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-19
lines changed

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+19-19Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def _on_move(self, event):
10491049

10501050
x, y = event.xdata, event.ydata
10511051
# In case the mouse is out of bounds.
1052-
if x is None:
1052+
if x is None or event.inaxes != self:
10531053
return
10541054

10551055
dx, dy = x - self.sx, y - self.sy
@@ -1083,7 +1083,7 @@ def _on_move(self, event):
10831083
elif self.button_pressed in self._zoom_btn:
10841084
# zoom view (dragging down zooms in)
10851085
scale = h/(h - dy)
1086-
self._zoom_data_limits(scale)
1086+
self._zoom_data_limits(scale, scale)
10871087

10881088
# Store the event coordinates for the next time through.
10891089
self.sx, self.sy = x, y
@@ -1104,23 +1104,20 @@ def drag_pan(self, button, key, x, y):
11041104
dx, dy = xdata - xdata_start, ydata - ydata_start
11051105
if dx == 0 and dy == 0:
11061106
return
1107-
1108-
# Now pan the view by updating the limits
1109-
w = self._pseudo_w
1110-
h = self._pseudo_h
1111-
1112-
minx, maxx, miny, maxy, minz, maxz = self.get_w_lims()
1113-
dx = 1 - ((w - dx) / w)
1114-
dy = 1 - ((h - dy) / h)
11151107
dz = 0
1108+
1109+
# Transform the pan into view-projected coordinates
11161110
u, v, n = self._get_view_axes(self.eye)
1111+
U, V, N = -np.array([u, v, n]) / self._box_aspect * self._dist
1112+
dxyz_projected = dx*U + dy*V + dz*N
11171113

1118-
dxyz_projected = -dx*u -dy*v -dz*n
1114+
# Calculate pan distance
1115+
minx, maxx, miny, maxy, minz, maxz = self.get_w_lims()
11191116
dxx = (maxx - minx) * dxyz_projected[0]
11201117
dyy = (maxy - miny) * dxyz_projected[1]
11211118
dzz = (maxz - minz) * dxyz_projected[2]
11221119

1123-
# pan
1120+
# Set the new axis limits
11241121
self.set_xlim3d(minx + dxx, maxx + dxx)
11251122
self.set_ylim3d(miny + dyy, maxy + dyy)
11261123
self.set_zlim3d(minz + dzz, maxz + dzz)
@@ -1159,11 +1156,11 @@ def _set_view_from_bbox(self, bbox, direction='in',
11591156
# Calculate zoom level
11601157
scale_x = abs((start_x - stop_x)/(self.bbox.max[0] - self.bbox.min[0]))
11611158
scale_y = abs((start_y - stop_y)/(self.bbox.max[1] - self.bbox.min[1]))
1162-
scale = max(scale_x, scale_y)
11631159
if direction == 'out':
1164-
scale = 1 / scale
1160+
scale_x = 1 / scale_x
1161+
scale_y = 1 / scale_y
11651162

1166-
self._zoom_data_limits(scale)
1163+
self._zoom_data_limits(scale_x, scale_y)
11671164

11681165
def _prepare_view_from_bbox(self, bbox, direction='in',
11691166
mode=None, twinx=False, twiny=False):
@@ -1203,15 +1200,18 @@ def _prepare_view_from_bbox(self, bbox, direction='in',
12031200

12041201
return bbox
12051202

1206-
def _zoom_data_limits(self, scale):
1203+
def _zoom_data_limits(self, scale_x, scale_y, scale_z=1):
12071204
# hmmm..this needs some help from clipping....
1205+
u, v, n = self._get_view_axes(self.eye)
1206+
scale = np.abs(scale_x*u + scale_y*v + scale_z*n)
1207+
12081208
minx, maxx, miny, maxy, minz, maxz = self.get_w_lims()
12091209
cx = (maxx + minx)/2
12101210
cy = (maxy + miny)/2
12111211
cz = (maxz + minz)/2
1212-
dx = (maxx - minx)*scale/2
1213-
dy = (maxy - miny)*scale/2
1214-
dz = (maxz - minz)*scale/2
1212+
dx = (maxx - minx)*scale[0]/2
1213+
dy = (maxy - miny)*scale[1]/2
1214+
dz = (maxz - minz)*scale[2]/2
12151215
self.set_xlim3d(cx - dx, cx + dx)
12161216
self.set_ylim3d(cy - dy, cy + dy)
12171217
self.set_zlim3d(cz - dz, cz + dz)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.