diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index adbf440cb131..3e71bba75a27 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4187,7 +4187,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, if (c_none or co is not None or isinstance(c, str) or - (isinstance(c, collections.Iterable) and + (isinstance(c, collections.Iterable) and len(c) > 0 and isinstance(c[0], str))): c_array = None else: diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b4879e3b208a..679f6e42d1eb 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1741,6 +1741,11 @@ def test_scatter_color(self): with pytest.raises(ValueError): plt.scatter([1, 2, 3], [1, 2, 3], color=[1, 2, 3]) + def test_scatter_empty(self): + # just making sure this does not raise an exception + plt.scatter([], []) + plt.scatter([], [], s=[], c=[]) + # Parameters for *test_scatter_c*. NB: assuming that the # scatter plot will have 4 elements. The tuple scheme is: # (*c* parameter case, exception regexp key or None if no exception)