8000 Tests, fix, and whats new from code review · matplotlib/matplotlib@b4e10e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4e10e6

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

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-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: 8 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
@@ -345,7 +350,7 @@ def _get_all_axis_line_edge_points(self, minmax, maxmin, axis_position=None):
345350
position='lower')
346351
edgep1_u, edgep2_u = self._get_axis_line_edge_points(minmax, maxmin,
347352
position='upper')
348-
if position in ('lower', 'both'):
353+
if axis_position in ('lower', 'both'):
349354
edgep1s.append(edgep1_l)
350355
edgep2s.append(edgep2_l)
351356
position.append('lower')
@@ -381,14 +386,14 @@ def _get_tickdir(self, position):
381386
tickdirs_base = [2, 2, 0]
382387
else:
383388
tickdirs_base = [1, 0, 0]
384-
if (0 <= azim_mod < 180):
389+
if 0 <= azim_mod < 180:
385390
tickdirs_base[2] = 1
386391
elif position == 'lower':
387392
if elev_mod >= 0:
388393
tickdirs_base = [1, 0, 1]
389394
else:
390395
tickdirs_base = [2, 2, 1]
391-
if (0 <= azim_mod < 180):
396+
if 0 <= azim_mod < 180:
392397
tickdirs_base[2] = 0
393398
info_i = [v["i"] for v in self._AXINFO.values()]
394399

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)
0