diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 1915d00bbedc..3791d373311b 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1,3 +1,4 @@ +import collections import functools import itertools import logging @@ -4184,7 +4185,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, valid_shape = True # will be put to the test! n_elem = -1 # used only for (some) exceptions - if c_none or co is not None: + if (c_none or + co is not None or + isinstance(c, str) or + (isinstance(c, collections.Iterable) and + isinstance(c[0], str))): c_array = None else: try: # First, does 'c' look suitable for value-mapping? diff --git a/lib/matplotlib/tests/baseline_images/test_axes/scatter.pdf b/lib/matplotlib/tests/baseline_images/test_axes/scatter.pdf index 814cde183aa2..dc4696597ed0 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/scatter.pdf and b/lib/matplotlib/tests/baseline_images/test_axes/scatter.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/scatter.png b/lib/matplotlib/tests/baseline_images/test_axes/scatter.png index f5cd0dd5a695..cbb8aaee5b1b 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/scatter.png and b/lib/matplotlib/tests/baseline_images/test_axes/scatter.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/scatter.svg b/lib/matplotlib/tests/baseline_images/test_axes/scatter.svg index a39062630deb..c11c4257d5db 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/scatter.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/scatter.svg @@ -1,8 +1,8 @@ - - + + - - - - + - + - + +" style="fill:#00ff00;stroke:#00ff00;"/> - - - - - - - - + + + + + - - + + + + + - - - - - - - - +L 0 3.5 +" id="m0dc7741f56" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - + - - - - - - - - - - + - - - - - - - - - + +L -3.5 0 +" id="mdcf66ab502" style="stroke:#000000;stroke-width:0.8;"/> - - - - - - - - - - - - + - - - - - - + - - - - - - - - - - - - + - - - - - - + - - - - - - - - - + - - - - - - + - - - - - - - - - + - - - - - - + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 5533cc0a5b25..6ba28e88e029 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1686,16 +1686,16 @@ def test_hist2d_transpose(): class TestScatter(object): - @image_comparison(baseline_images=['scatter', 'scatter']) + @image_comparison(baseline_images=['scatter'], + style='mpl20', remove_text=True) def test_scatter_plot(self): - fig, ax = plt.subplots() - data = {"x": [3, 4, 2, 6], "y": [2, 5, 2, 3], - "c": ['r', 'y', 'b', 'lime'], "s": [24, 15, 19, 29]} - - ax.scatter(data["x"], data["y"], c=data["c"], s=data["s"]) + data = {"x": np.array([3, 4, 2, 6]), "y": np.array([2, 5, 2, 3]), + "c": ['r', 'y', 'b', 'lime'], "s": [24, 15, 19, 29], + "c2": ['0.5', '0.6', '0.7', '0.8']} - # Reuse testcase from above for a labeled data test fig, ax = plt.subplots() + ax.scatter(data["x"] - 1., data["y"] - 1., c=data["c"], s=data["s"]) + ax.scatter(data["x"] + 1., data["y"] + 1., c=data["c2"], s=data["s"]) ax.scatter("x", "y", c="c", s="s", data=data) @image_comparison(baseline_images=['scatter_marker'], remove_text=True, @@ -1745,6 +1745,8 @@ def test_scatter_color(self): # scatter plot will have 4 elements. The tuple scheme is: # (*c* parameter case, exception regexp key or None if no exception) params_test_scatter_c = [ + # single string: + ('0.5', None), # Single letter-sequences ("rgby", None), ("rgb", "shape"), @@ -1763,6 +1765,10 @@ def test_scatter_color(self): ([0.5]*3, None), # should emit a warning for user's eyes though ([0.5]*4, None), # NB: no warning as matching size allows mapping ([0.5]*5, "shape"), + # list of strings: + (['0.5', '0.4', '0.6', '0.7'], None), + (['0.5', 'red', '0.6', 'C5'], None), + (['0.5', 0.5, '0.6', 'C5'], "conversion"), # RGB values ([[1, 0, 0]], None), ([[1, 0, 0]]*3, "shape"),