Skip to content

Commit fd8f239

Browse files
Align rotation of 3D plot by mouse with rolled axes
1 parent 2e034bf commit fd8f239

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,13 @@ def _on_move(self, event):
12671267
if self.button_pressed in self._rotate_btn:
12681268
# rotate viewing point
12691269
# get the x and y pixel coords
1270+
roll = np.deg2rad(self.roll)
12701271
if dx == 0 and dy == 0:
12711272
return
1272-
self.elev = art3d._norm_angle(self.elev - (dy/h)*180)
1273-
self.azim = art3d._norm_angle(self.azim - (dx/w)*180)
1273+
delev = (dy/h)*180*np.cos(roll) + (dx/w)*180*np.sin(roll)
1274+
dazim = -(dy/h)*180*np.sin(roll) + (dx/w)*180*np.cos(roll)
1275+
self.elev = art3d._norm_angle(self.elev - delev)
1276+
self.azim = art3d._norm_angle(self.azim - dazim)
12741277
self.get_proj()
12751278
self.stale = True
12761279
self.figure.canvas.draw_idle()
@@ -1285,7 +1288,6 @@ def _on_move(self, event):
12851288
dy = 1-((h - dy)/h)
12861289
elev = np.deg2rad(self.elev)
12871290
azim = np.deg2rad(self.azim)
1288-
roll = np.deg2rad(self.roll)
12891291
# project xv, yv, zv -> xw, yw, zw
12901292
dxx = (maxx-minx)*(dy*np.sin(elev)*np.cos(azim) + dx*np.sin(azim))
12911293
dyy = (maxy-miny)*(-dx*np.cos(azim) + dy*np.sin(elev)*np.sin(azim))

0 commit comments

Comments
 (0)