-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Correctly skip colors for nan points given to scatter #7570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
attn @efiring as you have been working in this code a lot recently. |
@@ -3996,7 +3996,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, | |||
colors = None # use cmap, norm after collection is created | |||
|
|||
# c will be unchanged unless it is the same length as x: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c and colors will be unchanged (why are c and colors different args?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a question you don't want to ask 😈 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More seriously, there it pre-dates me and is almost certainly to support back compatibility. c
can be a scalar, a color, a sequence of colors or a sequence of scalars. colors
can be (iirc) a single color or a list of colors.
c
comes from scatter being a scalar mappable under the hood and colors
comes from scatter returning a collection under the hood.
colors = np.array(['k', 'w', 'k']) | ||
s = plt.scatter(x, y, color=colors) | ||
facecolors = s.get_facecolors() | ||
assert_array_equal(facecolors[1], np.array([0, 0, 0, 1])) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
Actually plotting the figure in the test with red as the masked color:
which is clearly wrong... I'll try and look into this tomorrow. |
Looks like you missed the |
Okay, I think that's everything masked that needs to be. I couldn't work out whether to mask offsets or not so have left it alone. |
assert_array_equal(facecolors[1], np.array([0, 0, 0, 1])) | ||
assert_array_equal(linecolors[1], np.array([0, 0, 0, 1])) | ||
assert linewidths[1] == 3 |
There was a problem hiding this comment.
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(),
There was a problem hiding this comment.
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
?
Did you generate a new image to verify that it didn't do anything weird? And test with another marker at least informally? Also, travis and appveyor are at least somewhat failing on your tests, so please look at that. |
Yep, I have generated a new image locally to check nothing funny is happening any more. I'm baffled that any of the tests passed to be honest given I was never setting linewidths at all... should be fixed now. |
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
Fixes #3489. As far as I can tell the only problem was that
colors
was never being masked.