From 0b201e60ed6f327e81d3a970836b3b9784e76e7f Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 4 Dec 2016 22:09:18 +0000 Subject: [PATCH 1/6] Mask correct color array before scattering --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 2bf1bcc3e048..3ac47534ca5e 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3996,7 +3996,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, colors = None # use cmap, norm after collection is created # c will be unchanged unless it is the same length as x: - x, y, s, c = cbook.delete_masked_points(x, y, s, c) + x, y, s, colors = cbook.delete_masked_points(x, y, s, c) scales = s # Renamed for readability below. From cc5cbe57935739af4af5e18138f9bca2764e53c5 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 4 Dec 2016 22:20:39 +0000 Subject: [PATCH 2/6] Add a scatter masked colors test --- lib/matplotlib/tests/test_axes.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 005a88f91f4f..b6424bae0a66 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4841,3 +4841,13 @@ def test_color_length_mismatch(): c_rgb = (0.5, 0.5, 0.5) ax.scatter(x, y, c=c_rgb) ax.scatter(x, y, c=[c_rgb] * N) + + +@cleanup +def test_scatter_color_masking(): + x = np.array([1, 2, 3]) + y = np.array([1, np.nan, 3]) + colors = np.array(['k', 'w', 'k']) + s = plt.scatter(x, y, color=colors) + facecolors = s.get_facecolors() + assert_array_equal(facecolors[1], np.array([0, 0, 0, 1])) From d6c47af5a336b6f6ccb5aacc1e5de69e856a21c2 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 5 Dec 2016 20:26:24 +0000 Subject: [PATCH 3/6] Put back mask deletion for 'c' --- lib/matplotlib/axes/_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 3ac47534ca5e..e09443c68987 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3996,7 +3996,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, colors = None # use cmap, norm after collection is created # c will be unchanged unless it is the same length as x: - x, y, s, colors = cbook.delete_masked_points(x, y, s, c) + x, y, s, c, colors = cbook.delete_masked_points(x, y, s, c, colors) scales = s # Renamed for readability below. From ab11d0dbee7de385c7bc6bb5b03d3686d6079df4 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 6 Dec 2016 14:07:49 +0000 Subject: [PATCH 4/6] Also mask edgecolors --- lib/matplotlib/axes/_axes.py | 6 ++++-- lib/matplotlib/tests/test_axes.py | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index e09443c68987..1781eb929a4e 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3995,8 +3995,10 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, else: colors = None # use cmap, norm after collection is created - # c will be unchanged unless it is the same length as x: - x, y, s, c, colors = cbook.delete_masked_points(x, y, s, c, colors) + # s, c, colors, or edgecolors will be unchanged unless they are the + # same length as x: + maskargs = x, y, s, c, colors, edgecolors + x, y, s, c, colors, edgecolors = cbook.delete_masked_points(*maskargs) scales = s # Renamed for readability below. diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b6424bae0a66..466297a47f8c 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4849,5 +4849,8 @@ def test_scatter_color_masking(): y = np.array([1, np.nan, 3]) colors = np.array(['k', 'w', 'k']) s = plt.scatter(x, y, color=colors) + facecolors = s.get_facecolors() + linecolors = s.get_edgecolors() assert_array_equal(facecolors[1], np.array([0, 0, 0, 1])) + assert_array_equal(linecolors[1], np.array([0, 0, 0, 1])) From 7cabe139ddeeed6dc6904a8f2ebac84c5d03f9d4 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 6 Dec 2016 14:30:30 +0000 Subject: [PATCH 5/6] Finally, mask linewidths --- lib/matplotlib/axes/_axes.py | 9 +++++---- lib/matplotlib/tests/test_axes.py | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 1781eb929a4e..9ac722493750 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3995,10 +3995,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, else: colors = None # use cmap, norm after collection is created - # s, c, colors, or edgecolors will be unchanged unless they are the - # same length as x: - maskargs = x, y, s, c, colors, edgecolors - x, y, s, c, colors, edgecolors = cbook.delete_masked_points(*maskargs) + # Anything in maskargs will be unchanged unless it is the same length + # as x: + maskargs = x, y, s, c, colors, edgecolors, linewidths + x, y, s, c, colors, edgecolors, linewidths =\ + cbook.delete_masked_points(*maskargs) scales = s # Renamed for readability below. diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 466297a47f8c..85138a980b9c 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4848,9 +4848,12 @@ def test_scatter_color_masking(): x = np.array([1, 2, 3]) y = np.array([1, np.nan, 3]) colors = np.array(['k', 'w', 'k']) + linewidths = np.array([1, 2, 3]) s = plt.scatter(x, y, color=colors) facecolors = s.get_facecolors() linecolors = s.get_edgecolors() + linewidths = s.get_linewidths() assert_array_equal(facecolors[1], np.array([0, 0, 0, 1])) assert_array_equal(linecolors[1], np.array([0, 0, 0, 1])) + assert linewidths[1] == 3 From e5469f5c9bc49cbb2450b68102c0a81fee3a5db3 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 9 Dec 2016 23:06:08 +0000 Subject: [PATCH 6/6] Fix scatter color masking test --- lib/matplotlib/tests/test_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 85138a980b9c..b0b94639ffe0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4849,7 +4849,7 @@ def test_scatter_color_masking(): y = np.array([1, np.nan, 3]) colors = np.array(['k', 'w', 'k']) linewidths = np.array([1, 2, 3]) - s = plt.scatter(x, y, color=colors) + s = plt.scatter(x, y, color=colors, linewidths=linewidths) facecolors = s.get_facecolors() linecolors = s.get_edgecolors()