8000 Merge pull request #23453 from oscargus/mplot3dtests · matplotlib/matplotlib@b45025d · GitHub
[go: up one dir, main page]

Skip to content

Commit b45025d

Browse files
authored
Merge pull request #23453 from oscargus/mplot3dtests
TST: Add more tests for mplot3d
2 parents 866c215 + abcd97a commit b45025d

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed
Loading

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1212
from matplotlib.testing.widgets import mock_event
1313
from matplotlib.collections import LineCollection, PolyCollection
14-
from matplotlib.patches import Circle
14+
from matplotlib.patches import Circle, PathPatch
15+
from matplotlib.path import Path
16+
from matplotlib.text import Text
1517

1618
import matplotlib.pyplot as plt
1719
import numpy as np
@@ -144,6 +146,17 @@ def test_contour3d():
144146
ax.set_zlim(-100, 100)
145147

146148

149+
@mpl3d_image_comparison(['contour3d_extend3d.png'])
150+
def test_contour3d_extend3d():
151+
fig = plt.figure()
152+
ax = fig.add_subplot(projection='3d')
153+
X, Y, Z = axes3d.get_test_data(0.05)
154+
ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm, extend3d=True)
155+
ax.set_xlim(-30, 30)
156+
ax.set_ylim(-20, 40)
157+
ax.set_zlim(-80, 80)
158+
159+
147160
@mpl3d_image_comparison(['contourf3d.png'])
148161
def test_contourf3d():
149162
fig = plt.figure()
@@ -1042,6 +1055,9 @@ def test_autoscale():
10421055
ax.set_autoscalez_on(True)
10431056
ax.plot([0, 2], [0, 2], [0, 2])
10441057
assert ax.get_w_lims() == (0, 1, -.1, 1.1, -.4, 2.4)
1058+
ax.autoscale(axis='x')
1059+
ax.plot([0, 2], [0, 2], [0, 2])
1060+
assert ax.get_w_lims() == (0, 2, -.1, 1.1, -.4, 2.4)
10451061

10461062

10471063
@pytest.mark.parametrize('axis', ('x', 'y', 'z'))
@@ -1656,6 +1672,83 @@ def test_computed_zorder():
16561672
ax.axis('off')
16571673

16581674

1675+
def test_format_coord():
1676+
fig = plt.figure()
1677+
ax = fig.add_subplot(projection='3d')
1678+
x = np.arange(10)
1679+
ax.plot(x, np.sin(x))
1680+
fig.canvas.draw()
1681+
assert ax.format_coord(0, 0) == 'x=1.8066, y=1.0367, z=−0.0553'
1682+
# Modify parameters
1683+
ax.view_init(roll=30, vertical_axis="y")
1684+
fig.canvas.draw()
1685+
assert ax.format_coord(0, 0) == 'x=9.1651, y=−0.9215, z=−0.0359'
1686+
# Reset parameters
1687+
ax.view_init()
1688+
fig.canvas.draw()
1689+
assert ax.format_coord(0, 0) == 'x=1.8066, y=1.0367, z=−0.0553'
1690+
1691+
1692+
def test_get_axis_position():
1693+
fig = plt.figure()
1694+
ax = fig.add_subplot(projection='3d')
1695+
x = np.arange(10)
1696+
ax.plot(x, np.sin(x))
1697+
fig.canvas.draw()
1698+
assert ax.get_axis_position() == (False, True, False)
1699+
1700+
1701+
def test_margins():
1702+
fig = plt.figure()
1703+
ax = fig.add_subplot(projection='3d')
1704+
ax.margins(0.2)
1705+
assert ax.margins() == (0.2, 0.2, 0.2)
1706+
ax.margins(0.1, 0.2, 0.3)
1707+
assert ax.margins() == (0.1, 0.2, 0.3)
1708+
ax.margins(x=0)
1709+
assert ax.margins() == (0, 0.2, 0.3)
1710+
ax.margins(y=0.1)
1711+
assert ax.margins() == (0, 0.1, 0.3)
1712+
ax.margins(z=0)
1713+
assert ax.margins() == (0, 0.1, 0)
1714+
1715+
1716+
def test_margins_errors():
1717+
fig = plt.figure()
1718+
ax = fig.add_subplot(projection='3d')
1719+
with pytest.raises(TypeError, match="Cannot pass"):
1720+
ax.margins(0.2, x=0.4, y=0.4, z=0.4)
1721+
with pytest.raises(TypeError, match="Must pass"):
1722+
ax.margins(0.2, 0.4)
1723+
1724+
1725+
@check_figures_equal(extensions=["png"])
1726+
def test_text_3d(fig_test, fig_ref):
1727+
ax = fig_ref.add_subplot(projection="3d")
1728+
txt = Text(0.5, 0.5, r'Foo bar $\int$')
1729+
art3d.text_2d_to_3d(txt, z=1)
1730+
ax.add_artist(txt)
1731+
assert txt.get_position_3d() == (0.5, 0.5, 1)
1732+
1733+
ax = fig_test.add_subplot(projection="3d")
1734+
t3d = art3d.Text3D(0.5, 0.5, 1, r'Foo bar $\int$')
1735+
ax.add_artist(t3d)
1736+
assert t3d.get_position_3d() == (0.5, 0.5, 1)
1737+
1738+
1739+
@check_figures_equal(extensions=["png"])
1740+
def test_pathpatch_3d(fig_test, fig_ref):
1741+
ax = fig_ref.add_subplot(projection="3d")
1742+
path = Path.unit_rectangle()
1743+
patch = PathPatch(path)
1744+
art3d.pathpatch_2d_to_3d(patch, z=(0, 0.5, 0.7, 1, 0), zdir='y')
1745+
ax.add_artist(patch)
1746+
1747+
ax = fig_test.add_subplot(projection="3d")
1748+
pp3d = art3d.PathPatch3D(path, zs=(0, 0.5, 0.7, 1, 0), zdir='y')
1749+
ax.add_artist(pp3d)
1750+
1751+
16591752
@image_comparison(baseline_images=['scatter_spiral.png'],
16601753
remove_text=True,
16611754
style='default')

0 commit comments

Comments
 (0)
0