diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index b0d7312bff3d..c165a3e1e453 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -360,7 +360,7 @@ def draw(self, renderer): if np.any(scale_mask): mask = np.broadcast_to( scale_mask, - (len(self._verts3d), *self._verts3d[0].shape) + (len(self._verts3d), *np.shape(self._verts3d[0])) ) xs3d, ys3d, zs3d = np.ma.array(self._verts3d, dtype=float, mask=mask).filled(np.nan) diff --git a/lib/mpl_toolkits/mplot3d/tests/test_art3d.py b/lib/mpl_toolkits/mplot3d/tests/test_art3d.py index aca943f9e0c0..c38f0c744531 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_art3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_art3d.py @@ -13,6 +13,18 @@ ) +def test_line3d_set_data_3d_list_with_nan(): + # Regression test for #32127: set_data_3d stores array-like as given, and + # draw must not require ndarray .shape when a coordinate is non-finite. + fig = plt.figure() + ax = fig.add_subplot(projection="3d") + line, = ax.plot([0.0], [0.0], [0.0]) + xs, ys, zs = [float("nan")], [float("nan")], [float("nan")] + line.set_data_3d(xs, ys, zs) + assert line.get_data_3d() == (xs, ys, zs) + fig.canvas.draw() + + @pytest.mark.parametrize("zdir, expected", [ ("x", (1, 0, 0)), ("y", (0, 1, 0)),