From b1a7e7be88899f668bae0a100a0e6d1e4be67590 Mon Sep 17 00:00:00 2001 From: tobias Date: Sun, 26 Nov 2023 20:36:56 +0100 Subject: [PATCH] Fix get_path for 3d artists This is a slightly adapted version of commit 1868c05e622ad521efd5671e47eef6bd35e0b8c9 --- lib/mpl_toolkits/mplot3d/art3d.py | 5 +++++ lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 4aff115b0c96..ea43549c33fa 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -448,6 +448,11 @@ def set_3d_properties(self, verts, zs=0, zdir='z'): for ((x, y), z) in zip(verts, zs)] def get_path(self): + # docstring inherited + # self._path2d is not initialized until do_3d_projection + if not hasattr(self, '_path2d'): + self.axes.M = self.axes.get_proj() + self.do_3d_projection() return self._path2d def do_3d_projection(self): diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index 4024eeddcf17..1c6bbdd91670 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -2112,6 +2112,16 @@ def test_scatter_spiral(): fig.canvas.draw() +def test_Poly3DCollection_get_path(): + # Smoke test to see that get_path does not raise + # See GH#27361 + fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) + p = Circle((0, 0), 1.0) + ax.add_patch(p) + art3d.pathpatch_2d_to_3d(p) + p.get_path() + + def test_Poly3DCollection_get_facecolor(): # Smoke test to see that get_facecolor does not raise # See GH#4067