diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index acbeca931c38..8fe6e7a9c10b 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -545,7 +545,7 @@ def set_3d_properties(self, zs, zdir): # # Grab the current sizes and linewidths to preserve them. self._sizes3d = self._sizes - self._linewidths3d = self._linewidths + self._linewidths3d = np.array(self._linewidths) xs, ys, zs = self._offsets3d # Sort the points based on z coordinates @@ -563,7 +563,7 @@ def set_sizes(self, sizes, dpi=72.0): def set_linewidth(self, lw): super().set_linewidth(lw) if not self._in_draw: - self._linewidth3d = lw + self._linewidths3d = np.array(self._linewidths) def get_depthshade(self): return self._depthshade diff --git a/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/scatter3d_linewidth.png b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/scatter3d_linewidth.png new file mode 100644 index 000000000000..c4c07dd9e8d6 Binary files /dev/null and b/lib/mpl_toolkits/tests/baseline_images/test_mplot3d/scatter3d_linewidth.png differ diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 505cb4f0c50f..19d4ca77cd1f 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -299,6 +299,30 @@ def test_scatter3d_color(): color='b', marker='s') +@mpl3d_image_comparison(['scatter3d_linewidth.png']) +def test_scatter3d_linewidth(): + fig = plt.figure() + ax = fig.add_subplot(projection='3d') + + # Check that array-like linewidth can be set + ax.scatter(np.arange(10), np.arange(10), np.arange(10), + marker='o', linewidth=np.arange(10)) + + +@check_figures_equal(extensions=['png']) +def test_scatter3d_linewidth_modification(fig_ref, fig_test): + # Changing Path3DCollection linewidths with array-like post-creation + # should work correctly. + ax_test = fig_test.add_subplot(projection='3d') + c = ax_test.scatter(np.arange(10), np.arange(10), np.arange(10), + marker='o') + c.set_linewidths(np.arange(10)) + + ax_ref = fig_ref.add_subplot(projection='3d') + ax_ref.scatter(np.arange(10), np.arange(10), np.arange(10), marker='o', + linewidths=np.arange(10)) + + @check_figures_equal(extensions=['png']) def test_scatter3d_modification(fig_ref, fig_test): # Changing Path3DCollection properties post-creation should work correctly.