Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a242b2

Browse files
authored
Merge pull request #19539 from efiring/scatter_edgecolor_nan
In scatter, fix single rgb edgecolors handling
2 parents 7ae79cc + c6c7c75 commit 9a242b2

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
@@ -4503,6 +4503,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
45034503
x, y, s, c, colors, edgecolors, linewidths = \
45044504
cbook._combine_masks(
45054505
x, y, s, c, colors, edgecolors, linewidths)
4506+
# Unmask edgecolors if it was actually a single RGB or RGBA.
4507+
if (x.size in (3, 4)
4508+
and np.ma.is_masked(edgecolors)
4509+
and not np.ma.is_masked(orig_edgecolor)):
4510+
edgecolors = edgecolors.data
45064511

45074512
scales = s # Renamed for readability below.
45084513

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)