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
7 changes: 5 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3995,8 +3995,11 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
else:
colors = None # use cmap, norm after collection is created

# c will be unchanged unless it is the same length as x:
x, y, s, c = cbook.delete_masked_points(x, y, s, c)
# Anything in maskargs will be unchanged unless it is the same length
# as x:
maskargs = x, y, s, c, colors, edgecolors, linewidths
x, y, s, c, colors, edgecolors, linewidths =\
cbook.delete_masked_points(*maskargs)

scales = s # Renamed for readability below.

Expand Down
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4841,3 +4841,19 @@ def test_color_length_mismatch():
c_rgb = (0.5, 0.5, 0.5)
ax.scatter(x, y, c=c_rgb)
ax.scatter(x, y, c=[c_rgb] * N)


@cleanup
def test_scatter_color_masking():
x = np.array([1, 2, 3])
y = np.array([1, np.nan, 3])
colors = np.array(['k', 'w', 'k'])
linewidths = np.array([1, 2, 3])
s = plt.scatter(x, y, color=colors, linewidths=linewidths)

facecolors = s.get_facecolors()
linecolors = s.get_edgecolors()
linewidths = s.get_linewidths()
assert_array_equal(facecolors[1], np.array([0, 0, 0, 1]))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably unnecessary, but what about a test that verifies it's the right facecolor for the right value? Just to ensure no weird shifting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is there a way to get the scatter points out from s? All I can see that might do it is s.get_paths(), but that seems to give arrays that are definitely not what I'm looking for...

@story645 story645 Dec 5, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ugh, unfortunately haven't found a direct way though there might be one. :( As much as I'm loath to suggest an image test, that seems to be the trick. Though the way to test the error you're seeing below is to use the s.get_edgecolors(), so maybe that'd be good enough?

assert_array_equal(linecolors[1], np.array([0, 0, 0, 1]))
assert linewidths[1] == 3

@story645 story645 Dec 6, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also maybe assert facecolors[0], name edgecolors = s.get_edgecolors(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think I'm missing something here - should I just rename facecolors to edgecolors?