Skip to content

Commit e34be8a

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 e34be8a

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

lib/mpl_toolkits/mplot3d/axis3d.py

+27-4
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,34 @@ 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:
246+
if highs[2]: # looking at -XY plane
247+
highs[0] = False
248+
highs[1] = True
249+
else: # looking at +XY plane
250+
highs[0] = True
251+
highs[1] = True
252+
elif vertical == 1:
253+
if highs[1]: # looking at +XZ plane
254+
highs[0] = True
255+
else: # looking at -XZ plane
256+
pass
257+
elif vertical == 0:
258+
if highs[0]: # looking at -YZ plane
259+
highs[1] = True
260+
else: # looking at +YZ plane
261+
pass
239262

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

lib/mpl_toolkits/tests/test_mplot3d.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ 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+
# (view, (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_proj_type('ortho')
76+
ax.view_init(elev=views[i][0], azim=views[i][1], roll=views[i][2])
77+
plt.tight_layout()
78+
79+
6380
@mpl3d_image_comparison(['bar3d.png'])
6481
def test_bar3d():
6582
fig = plt.figure()
@@ -1839,9 +1856,9 @@ def test_scatter_spiral():
18391856
[0.0, 0.0, -1.142857, 10.571429],
18401857
],
18411858
[
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]),
1859+
([-0.06329114, 0.06329114], [0.04746835, 0.04746835]),
1860+
([0.06329114, 0.06329114], [-0.04746835, 0.04746835]),
1861+
([-0.05617978, -0.06329114], [0.04213483, 0.04746835]),
18451862
],
18461863
[2, 2, 0],
18471864
),

0 commit comments

Comments
 (0)