Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fd4af7

Browse files
authored
Merge pull request #28326 from meeseeksmachine/auto-backport-of-pr-28041-on-v3.9.x
Backport PR #28041 on branch v3.9.x ([BUG]: Shift box_aspect according to vertical_axis)
2 parents 994be67 + ecdbc27 commit 5fd4af7

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def set_box_aspect(self, aspect, *, zoom=1):
383383
# of the axes in mpl3.8.
384384
aspect *= 1.8294640721620434 * 25/24 * zoom / np.linalg.norm(aspect)
385385

386-
self._box_aspect = aspect
386+
self._box_aspect = self._roll_to_vertical(aspect, reverse=True)
387387
self.stale = True
388388

389389
def apply_aspect(self, position=None):
@@ -1191,9 +1191,23 @@ def set_proj_type(self, proj_type, focal_length=None):
11911191
f"None for proj_type = {proj_type}")
11921192
self._focal_length = np.inf
11931193

1194-
def _roll_to_vertical(self, arr):
1195-
"""Roll arrays to match the different vertical axis."""
1196-
return np.roll(arr, self._vertical_axis - 2)
1194+
def _roll_to_vertical(
1195+
self, arr: "np.typing.ArrayLike", reverse: bool = False
1196+
) -> np.ndarray:
1197+
"""
1198+
Roll arrays to match the different vertical axis.
1199+
1200+
Parameters
1201+
----------
1202+
arr : ArrayLike
1203+
Array to roll.
1204+
reverse : bool, default: False
1205+
Reverse the direction of the roll.
1206+
"""
1207+
if reverse:
1208+
return np.roll(arr, (self._vertical_axis - 2) * -1)
1209+
else:
1210+
return np.roll(arr, (self._vertical_axis - 2))
11971211

11981212
def get_proj(self):
11991213
"""Create the projection matrix from the current viewing position."""

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,24 @@ def test_on_move_vertical_axis(vertical_axis: str) -> None:
23012301
)
23022302

23032303

2304+
@pytest.mark.parametrize(
2305+
"vertical_axis, aspect_expected",
2306+
[
2307+
("x", [1.190476, 0.892857, 1.190476]),
2308+
("y", [0.892857, 1.190476, 1.190476]),
2309+
("z", [1.190476, 1.190476, 0.892857]),
2310+
],
2311+
)
2312+
def test_set_box_aspect_vertical_axis(vertical_axis, aspect_expected):
2313+
ax = plt.subplot(1, 1, 1, projection="3d")
2314+
ax.view_init(elev=0, azim=0, roll=0, vertical_axis=vertical_axis)
2315+
ax.figure.canvas.draw()
2316+
2317+
ax.set_box_aspect(None)
2318+
2319+
np.testing.assert_allclose(aspect_expected, ax._box_aspect, rtol=1e-6)
2320+
2321+
23042322
@image_comparison(baseline_images=['arc_pathpatch.png'],
23052323
remove_text=True,
23062324
style='mpl20')

0 commit comments

Comments
 (0)