FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Standardize edge-on axis locations when viewing primary 3d axis planes by scottshambaugh · Pull Request #23644 · matplotlib/matplotlib · GitHub

Repository navigation

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

Filter by extension

Filter by extension .png  (2) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
20 changes: 16 additions & 4 deletions lib/mpl_toolkits/mplot3d/axis3d.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.
Viewer requires iframe.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
33 changes: 27 additions & 6 deletions lib/mpl_toolkits/tests/test_mplot3d.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL