10BC0 Backport PR #25481 on branch v3.7.x (Fix 3D set_aspect error cases) by meeseeksmachine · Pull Request #25630 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension 10BC0

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,8 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
ptp = np.ptp(view_intervals, axis=1)
if self._adjustable == 'datalim':
mean = np.mean(view_intervals, axis=1)
delta = max(ptp[ax_indices])
scale = self._box_aspect[ptp == delta][0]
deltas = delta * self._box_aspect / scale
scale = max(ptp[ax_indices] / self._box_aspect[ax_indices])
deltas = scale * self._box_aspect

for i, set_lim in enumerate((self.set_xlim3d,
self.set_ylim3d,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 21 additions & 19 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
image_comparison, remove_text=True, style='default')


def plot_cuboid(ax, scale):
# plot a rectangular cuboid with side lengths given by scale (x, y, z)
r = [0, 1]
pts = itertools.combinations(np.array(list(itertools.product(r, r, r))), 2)
for start, end in pts:
if np.sum(np.abs(start - end)) == r[1] - r[0]:
ax.plot3D(*zip(start*np.array(scale), end*np.array(scale)))


@check_figures_equal(extensions=["png"])
def test_invisible_axes(fig_test, fig_ref):
ax = fig_test.subplots(subplot_kw=dict(projection='3d'))
Expand All @@ -32,20 +41,19 @@ def test_invisible_axes(fig_test, fig_ref):

@mpl3d_image_comparison(['aspects.png'], remove_text=False)
def test_aspects():
aspects = ('auto', 'equal', 'equalxy', 'equalyz', 'equalxz')
fig, axs = plt.subplots(1, len(aspects), subplot_kw={'projection': '3d'})
aspects = ('auto', 'equal', 'equalxy', 'equalyz', 'equalxz', 'equal')
_, axs = plt.subplots(2, 3, subplot_kw={'projection': '3d'})

# Draw rectangular cuboid with side lengths [1, 1, 5]
r = [0, 1]
scale = np.array([1, 1, 5])
pts = itertools.combinations(np.array(list(itertools.product(r, r, r))), 2)
for start, end in pts:
if np.sum(np.abs(start - end)) == r[1] - r[0]:
for ax in axs:
ax.plot3D(*zip(start*scale, end*scale))
for i, ax in enumerate(axs):
for ax in axs.flatten()[0:-1]:
plot_cuboid(ax, scale=[1, 1, 5])
# plot a cube as well to cover github #25443
plot_cuboid(axs[1][2], scale=[1, 1, 1])

for i, ax in enumerate(axs.flatten()):
ax.set_title(aspects[i])
ax.set_box_aspect((3, 4, 5))
ax.set_aspect(aspects[i], adjustable='datalim')
axs[1][2].set_title('equal (cube)')


@mpl3d_image_comparison(['aspects_adjust_box.png'], remove_text=False)
Expand All @@ -54,15 +62,9 @@ def test_aspects_adjust_box():
fig, axs = plt.subplots(1, len(aspects), subplot_kw={'projection': '3d'},
figsize=(11, 3))

# Draw rectangular cuboid with side lengths [4, 3, 5]
r = [0, 1]
scale = np.array([4, 3, 5])
pts = itertools.combinations(np.array(list(itertools.product(r, r, r))), 2)
for start, end in pts:
if np.sum(np.abs(start - end)) == r[1] - r[0]:
for ax in axs:
ax.plot3D(*zip(start*scale, end*scale))
for i, ax in enumerate(axs):
plot_cuboid(ax, scale=[4, 3, 5])
ax.set_title(aspects[i])
ax.set_aspect(aspects[i], adjustable='box')


Expand Down
0