Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a similar block for colors as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that is already an (N,4) array out of _parse_scatter_color_args and should have broadcast correctly with the masks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because the case that was problematic for colors was the case where edgecolors was being
set from colors, above all this. So handling edgecolors here takes care of it.

and np.ma.is_masked(edgecolors)
and not np.ma.is_masked(orig_edgecolor)):
edgecolors = edgecolors.data

scales = s # Renamed for readability below.

Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down