diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 4f050803f051..96b374144da4 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -507,8 +507,9 @@ def do_3d_projection(self, renderer): vzs = vzs[z_markers_idx] vxs = vxs[z_markers_idx] vys = vys[z_markers_idx] - fcs = fcs[z_markers_idx] - ecs = ecs[z_markers_idx] + if self._depthshade: + fcs = fcs[z_markers_idx] + ecs = ecs[z_markers_idx] if len(sizes) > 1: sizes = sizes[z_markers_idx] vps = np.column_stack((vxs, vys)) diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index f74df7e49d9c..6fa77c1758b8 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -242,6 +242,17 @@ def test_scatter3d_color(): color='b', marker='s') +def test_scatter3d_depthshade_false(): + """ + Test that 3d scatter plot doesn't throw + IndexError with depthshade=False (issue #18037) + """ + x = y = z = np.arange(16) + fig_test = plt.figure() + ax_test = fig_test.add_subplot(projection='3d') + ax_test.scatter(x, y, z, depthshade=False) + + @check_figures_equal(extensions=['png']) def test_scatter3d_size(fig_ref, fig_test): """Test that large markers in correct position (issue #18135)"""