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

Skip to content

Commit 724e80c

Browse files
Tests, fix, and whats new from code review
Code review commits Test image for axis positions
1 parent b62eb9b commit 724e80c

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

doc/users/next_whats_new/3d_axis_positions.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ You can now specify the positions of ticks and axis labels for 3D plots.
88

99
import matplotlib.pyplot as plt
1010

11-
positions = ['default', 'upper', 'lower', 'both', 'none']
12-
fig, axs = plt.subplots(1, 5, subplot_kw={'projection': '3d'})
13-
for ax, pos in zip(axs, positions):
11+
positions = ['lower', 'upper', 'default', 'both', 'none']
12+
fig, axs = plt.subplots(2, 3, figsize=(12, 8),
13+
subplot_kw={'projection': '3d'})
14+
for ax, pos in zip(axs.flatten(), positions):
1415
for axis in ax.xaxis, ax.yaxis, ax.zaxis:
15-
axis._label_position = pos
16-
axis._tick_position = pos
17-
ax.set(xlabel='x', ylabel='y', zlabel='z', title=pos)
16+
axis.set_label_position(pos)
17+
axis.set_ticks_position(pos)
18+
title = f'position="{pos}"'
19+
ax.set(xlabel='x', ylabel='y', zlabel='z', title=title)
20+
axs[1, 2].axis('off')

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ def set_ticks_position(self, position):
195195
str : {'lower', 'upper', 'both', 'default', 'none'}
196196
The position of the bolded axis lines, ticks, and tick labels.
197197
"""
198+
if position in ['top', 'bottom']:
199+
_api.warn_deprecated('3.8', name=f'{position=}',
200+
obj_type='argument value',
201+
alternative="'upper' or 'lower'")
202+
return
198203
_api.check_in_list(['lower', 'upper', 'both', 'default', 'none'],
199204
position=position)
200205
self._tick_position = position
@@ -219,6 +224,11 @@ def set_label_position(self, position):
219224
str : {'lower', 'upper', 'both', 'default', 'none'}
220225
The position of the axis label.
221226
"""
227+
if position in ['top', 'bottom']:
228+
_api.warn_deprecated('3.8', name=f'{position=}',
229+
obj_type='argument value',
230+
alternative="'upper' or 'lower'")
231+
return
222232
_api.check_in_list(['lower', 'upper', 'both', 'default', 'none'],
223233
position=position)
224234
self._label_position = position
@@ -345,7 +355,7 @@ def _get_all_axis_line_edge_points(self, minmax, maxmin, axis_position=None):
345355
position='lower')
346356
edgep1_u, edgep2_u = self._get_axis_line_edge_points(minmax, maxmin,
347357
position='upper')
348-
if position in ('lower', 'both'):
358+
if axis_position in ('lower', 'both'):
349359
edgep1s.append(edgep1_l)
350360
edgep2s.append(edgep2_l)
351361
position.append('lower')
@@ -381,14 +391,14 @@ def _get_tickdir(self, position):
381391
tickdirs_base = [2, 2, 0]
382392
else:
383393
tickdirs_base = [1, 0, 0]
384-
if (0 <= azim_mod < 180):
394+
if 0 <= azim_mod < 180:
385395
tickdirs_base[2] = 1
386396
elif position == 'lower':
387397
if elev_mod >= 0:
388398
tickdirs_base = [1, 0, 1]
389399
else:
390400
tickdirs_base = [2, 2, 1]
391-
if (0 <= azim_mod < 180):
401+
if 0 <= azim_mod < 180:
392402
tickdirs_base[2] = 0
393403
info_i = [v["i"] for v in self._AXINFO.values()]
394404

93.6 KB
Loading

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ def test_invisible_ticks_axis():
5757
axis.line.set_visible(False)
5858

5959

60+
@mpl3d_image_comparison(['axis_positions.png'], remove_text=False, style='mpl20')
61+
def test_axis_positions():
62+
positions = ['upper', 'lower', 'both', 'none']
63+
fig, axs = plt.subplots(2, 2, subplot_kw={'projection': '3d'})
64+
for ax, pos in zip(axs.flatten(), positions):
65+
for axis in ax.xaxis, ax.yaxis, ax.zaxis:
66+
axis.set_label_position(pos)
67+
axis.set_ticks_position(pos)
68+
title = f'{pos}'
69+
ax.set(xlabel='x', ylabel='y', zlabel='z', title=title)
70+
71+
6072
@mpl3d_image_comparison(['aspects.png'], remove_text=False, style='mpl20')
6173
def test_aspects():
6274
aspects = ('auto', 'equal', 'equalxy', 'equalyz', 'equalxz', 'equal')

0 commit comments

Comments
 (0)