Skip to content

Commit c6c7c75

Browse files
committed
In scatter, fix single rgb edgecolors handling
Closes #19066.
1 parent aa413a8 commit c6c7c75

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4507,6 +4507,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
45074507
x, y, s, c, colors, edgecolors, linewidths = \
45084508
cbook._combine_masks(
45094509
x, y, s, c, colors, edgecolors, linewidths)
4510+
# Unmask edgecolors if it was actually a single RGB or RGBA.
4511+
if (x.size in (3, 4)
4512+
and np.ma.is_masked(edgecolors)
4513+
and not np.ma.is_masked(orig_edgecolor)):
4514+
edgecolors = edgecolors.data
45104515

45114516
scales = s # Renamed for readability below.
45124517

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,6 +2172,15 @@ def test_scatter_size_arg_size(self):
21722172
with pytest.raises(ValueError, match='float array-like'):
21732173
plt.scatter(x, x, 'foo')
21742174

2175+
def test_scatter_edgecolor_RGB(self):
2176+
# Github issue 19066
2177+
coll = plt.scatter([1, 2, 3], [1, np.nan, np.nan],
2178+
edgecolor=(1, 0, 0))
2179+
assert mcolors.same_color(coll.get_edgecolor(), (1, 0, 0))
2180+
coll = plt.scatter([1, 2, 3, 4], [1, np.nan, np.nan, 1],
2181+
edgecolor=(1, 0, 0, 1))
2182+
assert mcolors.same_color(coll.get_edgecolor(), (1, 0, 0, 1))
2183+
21752184
@check_figures_equal(extensions=["png"])
21762185
def test_scatter_invalid_color(self, fig_test, fig_ref):
21772186
ax = fig_test.subplots()

0 commit comments

Comments
 (0)