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 bb95903

Browse filesBrowse files
Rework zooming for 3d plots
1 parent acbec0c commit bb95903
Copy full SHA for bb95903

File tree

Expand file treeCollapse file tree

2 files changed

+22
-15
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-15
lines changed

‎lib/mpl_toolkits/mplot3d/axes3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+16-15Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,6 @@ def _on_move(self, event):
10681068
dazim = -(dy/h)*180*np.sin(roll) - (dx/w)*180*np.cos(roll)
10691069
self.elev = self.elev + delev
10701070
self.azim = self.azim + dazim
1071-
self.get_proj()
10721071
self.stale = True
10731072

10741073
elif self.button_pressed in self._pan_btn:
@@ -1083,7 +1082,7 @@ def _on_move(self, event):
10831082
elif self.button_pressed in self._zoom_btn:
10841083
# zoom view (dragging down zooms in)
10851084
scale = h/(h - dy)
1086-
self._zoom_data_limits(scale, scale)
1085+
self._zoom_data_limits(scale, scale, scale)
10871086

10881087
# Store the event coordinates for the next time through.
10891088
self.sx, self.sy = x, y
@@ -1106,7 +1105,7 @@ def drag_pan(self, button, key, x, y):
11061105
return
11071106
dz = 0
11081107

1109-
# Transform the pan into view-projected coordinates
1108+
# Transform the pan from the view axes to the data axees
11101109
u, v, n = self._get_view_axes(self.eye)
11111110
U, V, N = -np.array([u, v, n]) / self._box_aspect * self._dist
11121111
dxyz_projected = dx*U + dy*V + dz*N
@@ -1121,7 +1120,6 @@ def drag_pan(self, button, key, x, y):
11211120
self.set_xlim3d(minx + dxx, maxx + dxx)
11221121
self.set_ylim3d(miny + dyy, maxy + dyy)
11231122
self.set_zlim3d(minz + dzz, maxz + dzz)
1124-
self.get_proj()
11251123

11261124
def _get_view_axes(self, eye):
11271125
elev_rad = np.deg2rad(art3d._norm_angle(self.elev))
@@ -1154,8 +1152,8 @@ def _set_view_from_bbox(self, bbox, direction='in',
11541152
self.end_pan()
11551153

11561154
# Calculate zoom level
1157-
scale_x = abs((start_x - stop_x)/(self.bbox.max[0] - self.bbox.min[0]))
1158-
scale_y = abs((start_y - stop_y)/(self.bbox.max[1] - self.bbox.min[1]))
1155+
scale_x = abs(start_x - stop_x) / (self.bbox.max[0] - self.bbox.min[0])
1156+
scale_y = abs(start_y - stop_y) / (self.bbox.max[1] - self.bbox.min[1])
11591157
if direction == 'out':
11601158
scale_x = 1 / scale_x
11611159
scale_y = 1 / scale_y
@@ -1201,21 +1199,24 @@ def _prepare_view_from_bbox(self, bbox, direction='in',
12011199
return bbox
12021200

12031201
def _zoom_data_limits(self, scale_x, scale_y, scale_z=1):
1204-
# hmmm..this needs some help from clipping....
1202+
# Convert from the scale factors in the view frame to the data frame
12051203
u, v, n = self._get_view_axes(self.eye)
1206-
scale = np.abs(scale_x*u + scale_y*v + scale_z*n)
1204+
R = np.array([u, v, n])
1205+
S = np.array([scale_x, scale_y, scale_z])
1206+
scale = np.linalg.norm(R.T@(np.eye(3)*S), axis=1)
12071207

1208+
# Scale the data range
12081209
minx, maxx, miny, maxy, minz, maxz = self.get_w_lims()
1210+
dxyz = np.array([maxx - minx, maxy - miny, maxz - minz])
1211+
dxyz_scaled = dxyz*scale
1212+
1213+
# Set the axis limits
12091214
cx = (maxx + minx)/2
12101215
cy = (maxy + miny)/2
12111216
cz = (maxz + minz)/2
1212-
dx = (maxx - minx)*scale[0]/2
1213-
dy = (maxy - miny)*scale[1]/2
1214-
dz = (maxz - minz)*scale[2]/2
1215-
self.set_xlim3d(cx - dx, cx + dx)
1216-
self.set_ylim3d(cy - dy, cy + dy)
1217-
self.set_zlim3d(cz - dz, cz + dz)
1218-
self.get_proj()
1217+
self.set_xlim3d(cx - dxyz_scaled[0]/2, cx + dxyz_scaled[0]/2)
1218+
self.set_ylim3d(cy - dxyz_scaled[1]/2, cy + dxyz_scaled[1]/2)
1219+
self.set_zlim3d(cz - dxyz_scaled[2]/2, cz + dxyz_scaled[2]/2)
12191220

12201221
def set_zlabel(self, zlabel, fontdict=None, labelpad=None, **kwargs):
12211222
"""

‎lib/mpl_toolkits/mplot3d/proj3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/proj3d.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ def rotation_about_vector(v, angle):
7373

7474

7575
def view_axes(E, R, V, roll):
76+
'''
77+
u, v, and n are the view axes
78+
u is towards the right
79+
v is towards the top
80+
n is the vector out of the screen
81+
'''
7682
n = (E - R)
7783
n = n/np.linalg.norm(n)
7884
u = np.cross(V, n)

0 commit comments

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