Skip to content

Commit

Permalink
Add tests for roll, and for rotation using mouse
Browse files Browse the repository at this point in the history
Add tests for roll (test_axes3d_roll), for rotation using the mouse (test_rotate), and for rotation using the mouse when roll is nonzero (test_rotate_roll). The latter fails if the roll angle is passed with wrong units (issue matplotlib#28256).
  • Loading branch information
MischaMegens2 committed May 22, 2024
1 parent f28c345 commit d4bfc33
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,14 @@ def test_axes3d_rotated():
ax.view_init(90, 45, 0) # look down, rotated. Should be square


@mpl3d_image_comparison(['axes3d_roll.png'],
remove_text=False, style='mpl20')
def test_axes3d_roll():
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.view_init(0, 0, 45)


def test_plotsurface_1d_raises():
x = np.linspace(0.5, 10, num=100)
y = np.linspace(0.5, 10, num=100)
Expand Down Expand Up @@ -1766,6 +1774,51 @@ def test_shared_axes_retick():
assert ax2.get_zlim() == (-0.5, 2.5)


def test_rotate():
"""Test rotating using the left mouse button."""
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.view_init(0, 0, 0)
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()
print(ax._pseudo_w)
print(ax.elev)
assert ax.azim == -dx*180
assert ax.elev == -dy*180
assert ax.roll == 0


def test_rotate_roll():
"""Test rotating using the left mouse button, when roll is nonzero."""
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.view_init(0, 0, 30)
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 = np.deg2rad(ax.roll)
assert ax.elev == (-dy*180*np.cos(roll)+dx*180*np.sin(roll))
assert ax.azim == (-dy*180*np.sin(roll)-dx*180*np.cos(roll))
assert ax.roll == 30


def test_pan():
"""Test mouse panning using the middle mouse button."""

Expand Down

0 comments on commit d4bfc33

Please sign in to comment.