From c6c7c750aed84822cab5f7ad2bb7282e94308d6c Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Thu, 18 Feb 2021 13:08:06 -1000 Subject: [PATCH] In scatter, fix single rgb edgecolors handling Closes #19066. --- lib/matplotlib/axes/_axes.py | 5 +++++ lib/matplotlib/tests/test_axes.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 3a170e9e44c5..c7e0002053db 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4507,6 +4507,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, x, y, s, c, colors, edgecolors, linewidths = \ cbook._combine_masks( x, y, s, c, colors, edgecolors, linewidths) + # Unmask edgecolors if it was actually a single RGB or RGBA. + if (x.size in (3, 4) + and np.ma.is_masked(edgecolors) + and not np.ma.is_masked(orig_edgecolor)): + edgecolors = edgecolors.data scales = s # Renamed for readability below. diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 22775989a708..ed76af576f64 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -2172,6 +2172,15 @@ def test_scatter_size_arg_size(self): with pytest.raises(ValueError, match='float array-like'): plt.scatter(x, x, 'foo') + def test_scatter_edgecolor_RGB(self): + # Github issue 19066 + coll = plt.scatter([1, 2, 3], [1, np.nan, np.nan], + edgecolor=(1, 0, 0)) + assert mcolors.same_color(coll.get_edgecolor(), (1, 0, 0)) + coll = plt.scatter([1, 2, 3, 4], [1, np.nan, np.nan, 1], + edgecolor=(1, 0, 0, 1)) + assert mcolors.same_color(coll.get_edgecolor(), (1, 0, 0, 1)) + @check_figures_equal(extensions=["png"]) def test_scatter_invalid_color(self, fig_test, fig_ref): ax = fig_test.subplots()