From 5619fd947b95ef070e0e541c3247ec20e43f1daf Mon Sep 17 00:00:00 2001 From: Chiraag Balu <86278218+chiraagbalu@users.noreply.github.com> Date: Tue, 19 Sep 2023 23:06:04 -0700 Subject: [PATCH] Backport PR #26834: Fix Issue 26821: [Bug]: ValueError: The truth value... when an ndarray is passed to the color kwarg of axes3d.scatter --- lib/mpl_toolkits/mplot3d/axes3d.py | 2 +- lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index aeb6a66d2c98..a74c11f54e60 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -2374,7 +2374,7 @@ def scatter(self, xs, ys, zs=0, zdir='z', s=20, c=None, depthshade=True, xs, ys, zs, s, c, color = cbook.delete_masked_points( xs, ys, zs, s, c, kwargs.get('color', None) ) - if kwargs.get('color', None): + if kwargs.get("color") is not None: kwargs['color'] = color # For xs and ys, 2D scatter() will do the copying. diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index 1f8764cbab9d..9cebc8a33efc 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -2270,3 +2270,12 @@ def test_Poly3DCollection_init_value_error(): 'or both for shade to work.'): poly = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], float) c = art3d.Poly3DCollection([poly], shade=True) + + +def test_ndarray_color_kwargs_value_error(): + # smoke test + # ensures ndarray can be passed to color in kwargs for 3d projection plot + fig = plt.figure() + ax = fig.add_subplot(111, projection='3d') + ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1])) + fig.canvas.draw()