Scatter color: moving #10809 forward#12422
Conversation
|
#12293 is causing the merge conflict, and when I try to solve it via a rebase I run into a hard failure because the author name is missing on this commit: I'm sure all this can be straightened out, but I don't want to spend the time on it until the ultimate design is clear. |
| def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, | ||
| vmin=None, vmax=None, alpha=None, linewidths=None, | ||
| verts=None, edgecolors=None, | ||
| verts=None, edgecolors=None, plotinvalid=False, |
There was a problem hiding this comment.
can we make the key-word only now that we are 3only?
|
Indeed, this PR also fixes the issue with invalid coordinates. I'll look into the rebase. |
|
@efiring Can I force-push to your branch, or do you prefer that I open a new PR? For the record: the first commit (by @QiCuiHub) has no author name (I'm actually puzzled how you can create one given that git appears to reject such patches), so I exported it in patch format with manually edited the patch to add a username ( (resolving the merge conflicts along the way). I then rebased the rest of the commits on top of that. There are some other things I'd suggest changing (can handle them once the rebase is done):
|
|
@anntzer Go ahead and force-push. Thank you. |
04900f1 to
421b46a
Compare
|
Force-pushed the rebase; I'll work on the other items mentioned above. |
421b46a to
2de2c50
Compare
|
Handled all my own points above. |
55b0864 to
d3ebdd6
Compare
anntzer
left a comment
There was a problem hiding this comment.
Actually in this design plotnonfinite doesn't do anything; even when it is not set, nan-valued points will be plotted with the "bad" color.
Usually this won't have an effect as the default "bad" color is "none", but this can be seen with e.g.
cm = get_cmap("viridis", 16); cm.set_bad("k")
scatter(range(3), range(3), c=[0, np.nan, 1], cmap=cm)
Given that the "default" behavior is not changed and that plotnonfinite doesn't really achieve anything, perhaps we should just not add that flag?
|
@anntzer Good point--I missed that. It appears to mean, however, that the Collection is not handling masked arrays as offsets the way I thought it was--it must be ignoring the masking. I thought I checked that when I started this PR. On the other hand, presumably the reason that scatter deletes points (I think I wrote that part long ago) is that originally masked offsets were not respected. |
|
Just to clarify:
Agreed in the understanding of the situation? Agree with the strategy in 3? |
|
@anntzer I do not agree with the strategy in 3, because with or without that strategy the PR is based on a false premise and is supplying masked arrays in a context where the masks are ignored. Either the Collection should be modified to accept masked arrays, or scatter should be modified to not supply them. I would like to investigate both possibilities, with a bias toward the former. I realize that in many lower-level places masked arrays end up replaced by floating-point arrays with NaNs, in part because they are easier to handle in C++ code. If that conversion is what is needed here, then it is just a question of where that conversion should occur. |
|
Looking at how e.g. Line2D handle masked arrays, they actually have to keep both the masked and unmasked-nan-filled versions around (self._xorig/self._x) because indeed there is no "simple" C-API for the masked arrays (and also because xorig is unitful whereas x is unitless), and then do a careful dance to keep track of modifications to them. |
|
Ok, did only read the full thread after reviewing the code 😏. Comments withdrawn as there are more fundamental issues to discuss first. |
|
It turns out that Collection was handling masked arrays as intended, but there was a bug in scatter, and one in its helper, _combine_masks. In addition to fixing those (I hope), I added a test for the plotnonfinite=False case. |
|
Indeed, looks like this fixes most issues. |
… updated - Fixed ambiguous kwarg to a more appropriate, less ambiguous name -> plotinvalid
The name is a reference to the standard isfinite() function.
Prior to this, examples/units/basic_units.py was not actually handling masked arrays, and units_scatter.py was not plotting its third panel correctly.
aa6f6ee to
a2cec14
Compare
|
I force pushed the branch with the image edited out, but the rest of the commit still here. |
PR Summary
This is a minimal update plus fixup for #10809, followed by a changeset to address #10381.
Along the way, it turned out that examples/units/units_scatter.py was doubly broken. It purported to show masked array support by basic_units.py, but didn't, because the support didn't exist; and it's third panel labeled the y-axis as Minutes but showed the values in Hz. Both of these problems are fixed in this PR.
PR Checklist