Skip to content

Commit e09a6f7

Browse files
committed
Merge pull request #7570 from dstansby/scatter-nan-colors
MNT: Correctly skip colors for nan points given to scatter Conflicts: lib/matplotlib/tests/test_axes.py Conflicts due to tests added on both branches
1 parent 4b53790 commit e09a6f7

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
@@ -3986,8 +3986,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
39863986
else:
39873987
colors = None # use cmap, norm after collection is created
39883988

3989-
# c will be unchanged unless it is the same length as x:
3990-
x, y, s, c = cbook.delete_masked_points(x, y, s, c)
3989+
# Anything in maskargs will be unchanged unless it is the same length
3990+
# as x:
3991+
maskargs = x, y, s, c, colors, edgecolors, linewidths
3992+
x, y, s, c, colors, edgecolors, linewidths =\
3993+
cbook.delete_masked_points(*maskargs)
39913994

39923995
scales = s # Renamed for readability below.
39933996

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,6 +4785,22 @@ def test_log_margins():
47854785
assert_allclose([xlim0t + delta, xlim1t - delta], [x0t, x1t])
47864786

47874787

4788+
@cleanup
4789+
def test_scatter_color_masking():
4790+
x = np.array([1, 2, 3])
4791+
y = np.array([1, np.nan, 3])
4792+
colors = np.array(['k', 'w', 'k'])
4793+
linewidths = np.array([1, 2, 3])
4794+
s = plt.scatter(x, y, color=colors, linewidths=linewidths)
4795+
4796+
facecolors = s.get_facecolors()
4797+
linecolors = s.get_edgecolors()
4798+
linewidths = s.get_linewidths()
4799+
assert_array_equal(facecolors[1], np.array([0, 0, 0, 1]))
4800+
assert_array_equal(linecolors[1], np.array([0, 0, 0, 1]))
4801+
assert linewidths[1] == 3
4802+
4803+
47884804
if __name__ == '__main__':
47894805
import nose
47904806
import sys

0 commit comments

Comments
 (0)