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

Skip to content

Commit 14bd014

Browse files
Put edge-on axes on left and right when viewing 3d axis planes
Tests Fix broken tests Clean up test
1 parent 2da3401 commit 14bd014

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,23 @@ def _get_coord_info(self, renderer):
231231
bounds_proj = self.axes.tunit_cube(bounds, self.axes.M)
232232

233233
# Determine which one of the parallel planes are higher up:
234-
highs = np.zeros(3, dtype=bool)
234+
means_z0 = np.zeros(3)
235+
means_z1 = np.zeros(3)
235236
for i in range(3):
236-
mean_z0 = np.mean(bounds_proj[self._PLANES[2 * i], 2])
237-
mean_z1 = np.mean(bounds_proj[self._PLANES[2 * i + 1], 2])
238-
highs[i] = mean_z0 < mean_z1
237+
means_z0[i] = np.mean(bounds_proj[self._PLANES[2 * i], 2])
238+
means_z1[i] = np.mean(bounds_proj[self._PLANES[2 * i + 1], 2])
239+
highs = means_z0 < means_z1
240+
241+
# Special handling for edge-on views
242+
equals = np.abs(means_z0 - means_z1) <= np.finfo(float).eps
243+
if np.sum(equals) == 2:
244+
vertical = np.where(np.invert(equals))[0][0]
245+
if vertical == 2: # looking at XY plane
246+
highs = np.array([True, True, highs[2]])
247+
elif vertical == 1: # looking at XZ plane
248+
highs = np.array([True, highs[1], False])
249+
elif vertical == 0: # looking at YZ plane
250+
highs = np.array([highs[0], False, False])
239251

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

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ def test_axes3d_repr():
6060
"title={'center': 'title'}, xlabel='x', ylabel='y', zlabel='z'>")
6161

6262

63+
@mpl3d_image_comparison(['axes3d_primary_views.png'])
64+
def test_axes3d_primary_views():
65+
# (elev, azim, roll)
66+
views = [(90, -90, 0), # XY
67+
(0, -90, 0), # XZ
68+
(0, 0, 0), # YZ
69+
(-90, 90, 0), # -XY
70+
(0, 90, 0), # -XZ
71+
(0, 180, 0)] # -YZ
72+
# When viewing primary planes, draw the two other axes on left and bottom
73+
fig, axs = plt.subplots(2, 3, subplot_kw={'projection': '3d'})
74+
for i, ax in enumerate([ax for ax_row in axs for ax in ax_row]):
75+
ax.set_xlabel('x')
76+
ax.set_ylabel('y')
77+
ax.set_zlabel('z')
78+
ax.set_proj_type('ortho')
79+
ax.view_init(elev=views[i][0], azim=views[i][1], roll=views[i][2])
80+
plt.tight_layout()
81+
82+
6383
@mpl3d_image_comparison(['bar3d.png'])
6484
def test_bar3d():
6585
fig = plt.figure()
@@ -1839,9 +1859,9 @@ def test_scatter_spiral():
18391859
[0.0, 0.0, -1.142857, 10.571429],
18401860
],
18411861
[
1842-
([0.06329114, -0.06329114], [-0.04746835, -0.04746835]),
1843-
([-0.06329114, -0.06329114], [0.04746835, -0.04746835]),
1844-
([0.05617978, 0.06329114], [-0.04213483, -0.04746835]),
1862+
([-0.06329114, 0.06329114], [0.04746835, 0.04746835]),
1863+
([0.06329114, 0.06329114], [-0.04746835, 0.04746835]),
1864+
([-0.05617978, -0.06329114], [0.04213483, 0.04746835]),
18451865
],
18461866
[2, 2, 0],
18471867
),
@@ -1854,9 +1874,9 @@ def test_scatter_spiral():
18541874
[0.0, -1.142857, 0.0, 10.571429],
18551875
],
18561876
[
1857-
([-0.06329114, -0.06329114], [-0.04746835, 0.04746835]),
1858-
([0.06329114, 0.05617978], [-0.04746835, -0.04213483]),
1859-
([0.06329114, -0.06329114], [-0.04746835, -0.04746835]),
1877+
([-0.06329114, -0.06329114], [0.04746835, -0.04746835]),
1878+
([0.06329114, 0.05617978], [0.04746835, 0.04213483]),
1879+
([0.06329114, -0.06329114], [0.04746835, 0.04746835]),
18601880
],
18611881
[1, 2, 1],
18621882
),

0 commit comments

Comments
 (0)