8000 Merge pull request #7570 from dstansby/scatter-nan-colors · matplotlib/matplotlib@f787c7a · GitHub
[go: up one dir, main page]

Skip to content

Commit f787c7a

Browse files
authored
Merge pull request #7570 from dstansby/scatter-nan-colors
MNT: Correctly skip colors for nan points given to scatter
2 parents 1b7bec6 + e5469f5 commit f787c7a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,8 +3995,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
39953995
else:
39963996
colors = None # use cmap, norm after collection is created
39973997

3998-
# c will be unchanged unless it is the same length as x:
3999-
x, y, s, c = cbook.delete_masked_points(x, y, s, c)
3998+
# Anything in maskargs will be unchanged unless it is the same length
3999+
# as x:
4000+
maskargs = x, y, s, c, colors, edgecolors, linewidths
4001+
x, y, s, c, colors, edgecolors, linewidths =\
4002+
cbook.delete_masked_points(*maskargs)
40004003

40014004
scales = s # Renamed for readability below.
40024005

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4836,3 +4836,19 @@ def test_color_length_mismatch():
48364836
c_rgb = (0.5, 0.5, 0.5)
48374837
ax.scatter(x, y, c=c_rgb)
48384838
ax.scatter(x, y, c=[c_rgb] * N)
4839+
4840+
4841+
@cleanup
4842+
def test_scatter_color_masking():
4843+
x = np.array([1, 2, 3])
4844+
y = np.array([1, np.nan, 3])
4845+
colors = np.array(['k', 'w', 'k'])
4846+
linewidths = np.array([1, 2, 3])
4847+
s = plt.scatter(x, y, color=colors, linewidths=linewidths)
4848+
4849+
facecolors = s.get_facecolors()
4850+
linecolors = s.get_edgecolors()
4851+
linewidths = s.get_linewidths()
4852+
assert_array_equal(facecolors[1], np.array([0, 0, 0, 1]))
4853+
assert_array_equal(linecolors[1], np.array([0, 0, 0, 1]))
4854+
assert linewidths[1] == 3

0 commit comments

Comments
 (0)
0