diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 2bf1bcc3e048..9ac722493750 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3995,8 +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 - # c will be unchanged unless it is the same length as x: - x, y, s, c = cbook.delete_masked_points(x, y, s, c) + # 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 005a88f91f4f..b0b94639ffe0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4841,3 +4841,19 @@ 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']) + linewidths = np.array([1, 2, 3]) + s = plt.scatter(x, y, color=colors, linewidths=linewidths) + + 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