From f28c34507c914ca567adc9fb7617ea3c6a6a74ed Mon Sep 17 00:00:00 2001 From: MischaMegens2 <122418839+MischaMegens2@users.noreply.github.com> Date: Sun, 19 May 2024 11:20:05 -0700 Subject: [PATCH 1/2] Fix roll angle units, issue #28256 Pass roll angle to view_init() in degrees (not radians) --- lib/mpl_toolkits/mplot3d/axes3d.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index d0f5c8d2b23b..677c2668d4e9 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1524,6 +1524,7 @@ def _on_move(self, event): dazim = -(dy/h)*180*np.sin(roll) - (dx/w)*180*np.cos(roll) elev = self.elev + delev azim = self.azim + dazim + roll = self.roll vertical_axis = self._axis_names[self._vertical_axis] self.view_init( elev=elev, From acd21ebb2de1cb9ff9f73618371f64ec38109031 Mon Sep 17 00:00:00 2001 From: MischaMegens2 <122418839+MischaMegens2@users.noreply.github.com> Date: Wed, 22 May 2024 08:42:05 -0700 Subject: [PATCH 2/2] Add test for rotation using mouse Add tests for rotation using the mouse (test_rotate), with and without roll. The test with nonzero roll fails if the roll angle is passed with wrong units (issue #28256). --- lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index ed56e5505d8e..c339e35e903c 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -1766,6 +1766,31 @@ def test_shared_axes_retick(): assert ax2.get_zlim() == (-0.5, 2.5) +def test_rotate(): + """Test rotating using the left mouse button.""" + for roll in [0, 30]: + fig = plt.figure() + ax = fig.add_subplot(1, 1, 1, projection='3d') + ax.view_init(0, 0, roll) + ax.figure.canvas.draw() + + # drag mouse horizontally to change azimuth + dx = 0.1 + dy = 0.2 + ax._button_press( + mock_event(ax, button=MouseButton.LEFT, xdata=0, ydata=0)) + ax._on_move( + mock_event(ax, button=MouseButton.LEFT, + xdata=dx*ax._pseudo_w, ydata=dy*ax._pseudo_h)) + ax.figure.canvas.draw() + roll_radians = np.deg2rad(ax.roll) + cs = np.cos(roll_radians) + sn = np.sin(roll_radians) + assert ax.elev == (-dy*180*cs + dx*180*sn) + assert ax.azim == (-dy*180*sn - dx*180*cs) + assert ax.roll == roll + + def test_pan(): """Test mouse panning using the middle mouse button."""