Skip to content

Standardize edge-on axis locations when viewing primary 3d axis planes #23644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,23 @@ def _get_coord_info(self, renderer):
bounds_proj = self.axes.tunit_cube(bounds, self.axes.M)

# Determine which one of the parallel planes are higher up:
highs = np.zeros(3, dtype=bool)
means_z0 = np.zeros(3)
means_z1 = np.zeros(3)
for i in range(3):
mean_z0 = np.mean(bounds_proj[self._PLANES[2 * i], 2])
mean_z1 = np.mean(bounds_proj[self._PLANES[2 * i + 1], 2])
highs[i] = mean_z0 < mean_z1
means_z0[i] = np.mean(bounds_proj[self._PLANES[2 * i], 2])
means_z1[i] = np.mean(bounds_proj[self._PLANES[2 * i + 1], 2])
highs = means_z0 < means_z1

# Special handling for edge-on views
equals = np.abs(means_z0 - means_z1) <= np.finfo(float).eps
if np.sum(equals) == 2:
vertical = np.where(~equals)[0][0]
if vertical == 2: # looking at XY plane
highs = np.array([True, True, highs[2]])
elif vertical == 1: # looking at XZ plane
highs = np.array([True, highs[1], False])
elif vertical == 0: # looking at YZ plane
highs = np.array([highs[0], False, False])

return mins, maxs, centers, deltas, bounds_proj, highs

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.
33 changes: 27 additions & 6 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ def test_axes3d_repr():
"title={'center': 'title'}, xlabel='x', ylabel='y', zlabel='z'>")


@mpl3d_image_comparison(['axes3d_primary_views.png'])
def test_axes3d_primary_views():
# (elev, azim, roll)
views = [(90, -90, 0), # XY
(0, -90, 0), # XZ
(0, 0, 0), # YZ
(-90, 90, 0), # -XY
(0, 90, 0), # -XZ
(0, 180, 0)] # -YZ
# When viewing primary planes, draw the two visible axes so they intersect
# at their low values
fig, axs = plt.subplots(2, 3, subplot_kw={'projection': '3d'})
for i, ax in enumerate(axs.flat):
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
ax.set_proj_type('ortho')
ax.view_init(elev=views[i][0], azim=views[i][1], roll=views[i][2])
plt.tight_layout()


@mpl3d_image_comparison(['bar3d.png'])
def test_bar3d():
fig = plt.figure()
Expand Down Expand Up @@ -1839,9 +1860,9 @@ def test_scatter_spiral():
[0.0, 0.0, -1.142857, 10.571429],
],
[
([0.06329114, -0.06329114], [-0.04746835, -0.04746835]),
([-0.06329114, -0.06329114], [0.04746835, -0.04746835]),
([0.05617978, 0.06329114], [-0.04213483, -0.04746835]),
([-0.06329114, 0.06329114], [0.04746835, 0.04746835]),
([0.06329114, 0.06329114], [-0.04746835, 0.04746835]),
([-0.05617978, -0.06329114], [0.04213483, 0.04746835]),
],
[2, 2, 0],
),
Expand All @@ -1854,9 +1875,9 @@ def test_scatter_spiral():
[0.0, -1.142857, 0.0, 10.571429],
],
[
([-0.06329114, -0.06329114], [-0.04746835, 0.04746835]),
([0.06329114, 0.05617978], [-0.04746835, -0.04213483]),
([0.06329114, -0.06329114], [-0.04746835, -0.04746835]),
([-0.06329114, -0.06329114], [0.04746835, -0.04746835]),
([0.06329114, 0.05617978], [0.04746835, 0.04213483]),
([0.06329114, -0.06329114], [0.04746835, 0.04746835]),
],
[1, 2, 1],
),
Expand Down