8000 Add tests for mplot3d and minor cleanup · matplotlib/matplotlib@431cdd6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 431cdd6

Browse files
committed
Add tests for mplot3d and minor cleanup
1 parent 51ce677 commit 431cdd6

File tree

3 files changed

+62
-18
lines changed

3 files changed

+62
-18
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ def draw(self, renderer):
393393

394394
# draw the background patch
395395
self.patch.draw(renderer)
396-
self._frameon = False
397396

398397
# first, set the aspect
399398
# this is duplicated from `axes._base._AxesBase.draw`
@@ -489,7 +488,7 @@ def margins(self, *margins, x=None, y=None, z=None, tight=True):
489488
applies to 3D Axes, it also takes a *z* argument, and returns
490489
``(xmargin, ymargin, zmargin)``.
491490
"""
492-
if margins and x is not None and y is not None and z is not None:
491+
if margins and (x is not None or y is not None or z is not None):
493492
raise TypeError('Cannot pass both positional and keyword '
494493
'arguments for x, y, and/or z.')
495494
elif len(margins) == 1:
@@ -816,7 +815,7 @@ def set_proj_type(self, proj_type, focal_length=None):
816815
raise ValueError(f"focal_length = {focal_length} must be "
817816
"greater than 0")
818817
self._focal_length = focal_length
819-
elif proj_type == 'ortho':
818+
else: # 'ortho'
820819
if focal_length not in (None, np.inf):
821820
raise ValueError(f"focal_length = {focal_length} must be "
822821
f"None for proj_type = {proj_type}")
@@ -1132,21 +1131,6 @@ def get_zlabel(self):
11321131

11331132
# Axes rectangle characteristics
11341133

1135-
def get_frame_on(self):
1136-
"""Get whether the 3D axes panels are drawn."""
1137-
return self._frameon
1138-
1139-
def set_frame_on(self, b):
1140-
"""
1141-
Set whether the 3D axes panels are drawn.
1142-
1143-
Parameters
1144-
----------
1145-
b : bool
1146-
"""
1147-
self._frameon = bool(b)
1148-
self.stale = True
1149-
11501134
@_api.rename_parameter("3.5", "b", "visible")
11511135
def grid(self, visible=True, **kwargs):
11521136
"""
62.7 KB
Loading

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ def test_contour3d():
131131
ax.set_zlim(-100, 100)
132132

133133

134+
@mpl3d_image_comparison(['contour3d_extend3d.png'])
135+
def test_contour3d_extend3d():
136+
fig = plt.figure()
137+
ax = fig.add_subplot(projection='3d')
138+
X, Y, Z = axes3d.get_test_data(0.05)
139+
ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm, extend3d=True)
140+
ax.set_xlim(-30, 30)
141+
ax.set_ylim(-20, 40)
142+
ax.set_zlim(-80, 80)
143+
144+
134145
@mpl3d_image_comparison(['contourf3d.png'])
135146
def test_contourf3d():
136147
fig = plt.figure()
@@ -1029,6 +1040,9 @@ def test_autoscale():
10291040
ax.set_autoscalez_on(True)
10301041
ax.plot([0, 2], [0, 2], [0, 2])
10311042
assert ax.get_w_lims() == (0, 1, -.1, 1.1, -.4, 2.4)
1043+
ax.autoscale(axis='x')
1044+
ax.plot([0, 2], [0, 2], [0, 2])
1045+
assert ax.get_w_lims() == (0, 2, -.1, 1.1, -.4, 2.4)
10321046

10331047

10341048
@pytest.mark.parametrize('axis', ('x', 'y', 'z'))
@@ -1643,6 +1657,52 @@ def test_computed_zorder():
16431657
ax.axis('off')
16441658

16451659

1660+
def test_format_coord():
1661+
fig = plt.figure()
1662+
ax = fig.add_subplot(projection='3d')
1663+
x = np.arange(10)
1664+
ax.plot(x, np.sin(x))
1665+
fig.canvas.draw()
1666+
assert ax.format_coord(0, 0) == 'x=1.8066, y=1.0367, z=−0.0553'
1667+
# Modify parameters
1668+
ax.view_init(roll=30, vertical_axis="y")
1669+
fig.canvas.draw()
1670+
assert ax.format_coord(0, 0) == 'x=9.1651, y=−0.9215, z=−0.0359'
1671+
# Reset parameters
1672+
ax.view_init()
1673+
fig.canvas.draw()
1674+
assert ax.format_coord(0, 0) == 'x=1.8066, y=1.0367, z=−0.0553'
1675+
1676+
1677+
def test_get_axis_position():
1678+
fig = plt.figure()
1679+
ax = fig.add_subplot(projection='3d')
1680+
x = np.arange(10)
1681+
ax.plot(x, np.sin(x))
1682+
fig.canvas.draw()
1683+
assert ax.get_axis_position() == (False, True, False)
1684+
1685+
1686+
def test_margins():
1687+
fig = plt.figure()
1688+
ax = fig.add_subplot(projection='3d')
1689+
ax.margins(0.2)
1690+
assert ax.margins() == (0.2, 0.2, 0.2)
1691+
ax.margins(0.1, 0.2, 0.3)
1692+
assert ax.margins() == (0.1, 0.2, 0.3)
1693+
ax.margins(x=0)
1694+
assert ax.margins() == (0, 0.2, 0.3)
1695+
1696+
1697+
def test_margins_errors():
1698+
fig = plt.figure()
1699+
ax = fig.add_subplot(projection='3d')
1700+
with pytest.raises(TypeError, match="Cannot pass"):
1701+
ax.margins(0.2, x=0.4)
1702+
with pytest.raises(TypeError, match="Must pass"):
1703+
ax.margins(0.2, 0.4)
1704+
1705+
16461706
@image_comparison(baseline_images=['scatter_spiral.png'],
16471707
remove_text=True,
16481708
style='default')

0 commit comments

Comments
 (0)
0