-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improper handling of color in set_color when data contains NaN. #9891
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
Comments
Thanks for the clear report. The |
I have a vague memory of a fix for this going in for 2.1. |
Sorry, should have said I reproduced in master. |
To elaborate: the strategy used by |
If filtering is done using a variety of input parameters, then I would think it would be even more important to keep track of the invalid data mask, so that data sets (with possible NaN values) could be used naturally with the programatic api. I think that doing so would greatly help with NaN support, but more generally help make the connection between data sets and plots simpler. In certain types of scientific analysis NaN is a valid and meaningful floating point value that needs to be retained as part of data sets. Requiring fre-filtering before plotting is of course an reasonable option, but then it would still seem that there should be consistency between the original call to scatter and the api. |
I agree that the inconsistency you point out is undesirable. The questions are, what are the options for removing the inconsistency, and is the trade-off involved in the best of these worth it? I think the simplest way to handle this might be to give collections one more optional initialization argument, a mask, which would then have to be applied in appropriate method calls, perhaps depending on an optional kwarg in the method call itself. A better alternative might be to warn about this inconsistency in the scatter docstring. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
This behaves as expected now, likely after the PR linked above. |
There is no PR directly linked above, but yes, it was fixed by #12422. |
Bug report
Bug summary
When a scatter plot is made with data that contains np.nan (NaN), and then a color array is given using
set_color
, the wrong colors get mapped to the data points.Code for reproduction
Actual outcome
Top: Expected colors with when x and y do not contain any np.nan.
Middle: Add some nan values. If the color array is given during the initial creation of the scatter plot, then everything works as expected.
Bottom: Again add some nan values. If the color array is given as a call to
set_color
then the colors no longer match the data.Expected outcome
The colors corresponding to the data points should be displayed, even when data points contain NaN and
set_color
is used.Matplotlib version
The text was updated successfully, but these errors were encountered: