|
11 | 11 | from matplotlib.testing.decorators import image_comparison, check_figures_equal |
12 | 12 | from matplotlib.testing.widgets import mock_event |
13 | 13 | 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 |
15 | 17 |
|
16 | 18 | import matplotlib.pyplot as plt |
17 | 19 | import numpy as np |
@@ -131,6 +133,17 @@ def test_contour3d(): |
131 | 133 | ax.set_zlim(-100, 100) |
132 | 134 |
|
133 | 135 |
|
| 136 | +@mpl3d_image_comparison(['contour3d_extend3d.png']) |
| 137 | +def test_contour3d_extend3d(): |
| 138 | + fig = plt.figure() |
| 139 | + ax = fig.add_subplot(projection='3d') |
| 140 | + X, Y, Z = axes3d.get_test_data(0.05) |
| 141 | + ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm, extend3d=True) |
| 142 | + ax.set_xlim(-30, 30) |
| 143 | + ax.set_ylim(-20, 40) |
| 144 | + ax.set_zlim(-80, 80) |
| 145 | + |
| 146 | + |
134 | 147 | @mpl3d_image_comparison(['contourf3d.png']) |
135 | 148 | def test_contourf3d(): |
136 | 149 | fig = plt.figure() |
@@ -1029,6 +1042,9 @@ def test_autoscale(): |
1029 | 1042 | ax.set_autoscalez_on(True) |
1030 | 1043 | ax.plot([0, 2], [0, 2], [0, 2]) |
1031 | 1044 | assert ax.get_w_lims() == (0, 1, -.1, 1.1, -.4, 2.4) |
| 1045 | + ax.autoscale(axis='x') |
| 1046 | + ax.plot([0, 2], [0, 2], [0, 2]) |
| 1047 | + assert ax.get_w_lims() == (0, 2, -.1, 1.1, -.4, 2.4) |
1032 | 1048 |
|
1033 | 1049 |
|
1034 | 1050 | @pytest.mark.parametrize('axis', ('x', 'y', 'z')) |
@@ -1643,6 +1659,83 @@ def test_computed_zorder(): |
1643 | 1659 | ax.axis('off') |
1644 | 1660 |
|
1645 | 1661 |
|
| 1662 | +def test_format_coord(): |
| 1663 | + fig = plt.figure() |
| 1664 | + ax = fig.add_subplot(projection='3d') |
| 1665 | + x = np.arange(10) |
| 1666 | + ax.plot(x, np.sin(x)) |
| 1667 | + fig.canvas.draw() |
| 1668 | + assert ax.format_coord(0, 0) == 'x=1.8066, y=1.0367, z=−0.0553' |
| 1669 | + # Modify parameters |
| 1670 | + ax.view_init(roll=30, vertical_axis="y") |
| 1671 | + fig.canvas.draw() |
| 1672 | + assert ax.format_coord(0, 0) == 'x=9.1651, y=−0.9215, z=−0.0359' |
| 1673 | + # Reset parameters |
| 1674 | + ax.view_init() |
| 1675 | + fig.canvas.draw() |
| 1676 | + assert ax.format_coord(0, 0) == 'x=1.8066, y=1.0367, z=−0.0553' |
| 1677 | + |
| 1678 | + |
| 1679 | +def test_get_axis_position(): |
| 1680 | + fig = plt.figure() |
| 1681 | + ax = fig.add_subplot(projection='3d') |
| 1682 | + x = np.arange(10) |
| 1683 | + ax.plot(x, np.sin(x)) |
| 1684 | + fig.canvas.draw() |
| 1685 | + assert ax.get_axis_position() == (False, True, False) |
| 1686 | + |
| 1687 | + |
| 1688 | +def test_margins(): |
| 1689 | + fig = plt.figure() |
| 1690 | + ax = fig.add_subplot(projection='3d') |
| 1691 | + ax.margins(0.2) |
| 1692 | + assert ax.margins() == (0.2, 0.2, 0.2) |
| 1693 | + ax.margins(0.1, 0.2, 0.3) |
| 1694 | + assert ax.margins() == (0.1, 0.2, 0.3) |
| 1695 | + ax.margins(x=0) |
| 1696 | + assert ax.margins() == (0, 0.2, 0.3) |
| 1697 | + ax.margins(y=0.1) |
| 1698 | + assert ax.margins() == (0, 0.1, 0.3) |
| 1699 | + ax.margins(z=0) |
| 1700 | + assert ax.margins() == (0, 0.1, 0) |
| 1701 | + |
| 1702 | + |
| 1703 | +def test_margins_errors(): |
| 1704 | + fig = plt.figure() |
| 1705 | + ax = fig.add_subplot(projection='3d') |
| 1706 | + with pytest.raises(TypeError, match="Cannot pass"): |
| 1707 | + ax.margins(0.2, x=0.4, y=0.4, z=0.4) |
| 1708 | + with pytest.raises(TypeError, match="Must pass"): |
| 1709 | + ax.margins(0.2, 0.4) |
| 1710 | + |
| 1711 | + |
| 1712 | +@check_figures_equal(extensions=["png"]) |
| 1713 | +def test_text_3d(fig_test, fig_ref): |
| 1714 | + ax = fig_ref.add_subplot(projection="3d") |
| 1715 | + txt = Text(0.5, 0.5, r'Foo bar $\int$') |
| 1716 | + art3d.text_2d_to_3d(txt, z=1) |
| 1717 | + ax.add_artist(txt) |
| 1718 | + assert txt.get_position_3d() == (0.5, 0.5, 1) |
| 1719 | + |
| 1720 | + ax = fig_test.add_subplot(projection="3d") |
| 1721 | + t3d = art3d.Text3D(0.5, 0.5, 1, r'Foo bar $\int$') |
| 1722 | + ax.add_artist(t3d) |
| 1723 | + assert t3d.get_position_3d() == (0.5, 0.5, 1) |
| 1724 | + |
| 1725 | + |
| 1726 | +@check_figures_equal(extensions=["png"]) |
| 1727 | +def test_pathpatch_3d(fig_test, fig_ref): |
| 1728 | + ax = fig_ref.add_subplot(projection="3d") |
| 1729 | + path = Path.unit_rectangle() |
| 1730 | + patch = PathPatch(path) |
| 1731 | + art3d.pathpatch_2d_to_3d(patch, z=(0, 0.5, 0.7, 1, 0), zdir='y') |
| 1732 | + ax.add_artist(patch) |
| 1733 | + |
| 1734 | + ax = fig_test.add_subplot(projection="3d") |
| 1735 | + pp3d = art3d.PathPatch3D(path, zs=(0, 0.5, 0.7, 1, 0), zdir='y') |
| 1736 | + ax.add_artist(pp3d) |
| 1737 | + |
| 1738 | + |
1646 | 1739 | @image_comparison(baseline_images=['scatter_spiral.png'], |
1647 | 1740 | remove_text=True, |
1648 | 1741 | style='default') |
|
0 commit comments