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
avoid np.nan values in colors array returned by axes3d._shade_colors #3031
avoid np.nan values in colors array returned by axes3d._shade_colors #3031
Conversation
@WeatherGod Can you take a look at this? |
If we are just simply silencing the warnings, why not just simply use numpy.errstate() context manager? http://docs.scipy.org/doc/numpy/reference/generated/numpy.errstate.html Or, if it isn't available in the earliest version of numpy we support (I can't remember what it is), then we can simply use np.geterr() and np.seterr() ourselves. It makes it more explicit what it is that we are doing. |
It seems we check for >= 1.5 |
This PR doesn't just silence warnings, it prevents the errors from happening. In particular the second change, which prevents '_shade_colors' from returning a colors array that contains nan values. |
Ah, right. Well, the problem I have with putting in an arbitrary value of zero is if the minimum shade value isn't zero, then the normalization will give a negative value for the norm() for anything zeroed, which might not look correct. Furthermore, it is entirely possible for this computation to produce a negative color, so we haven't really solved the problem. I wonder if masked arrays would be better here? the Normalize() object would already support that properly, I am just not entirely sure what the level of support is in colors.py for a masked array of RGBA values. |
That's a good point, shade shouldn't be set to zero without taking account for it in the normalization. Masked array might be a possible solution but a simpler solution without downsides as far as I can see would be to set |
avoid np.nan values in colors array returned by axes3d._shade_colors
Yup, that looks good. Thanks for the fix! |
Fix bug in Axes3D._shade_colors
There is a problem with handling NaN values in the shade array in on line 1677 in axes3d.py. If proj3d.mod(n) the corresponding value in shade is nan, and it is masked out from the shade array using
mask
on lines 1681 - 1682 but not line 1688. As a result the colors array will include nan values, and the following warnings are displayed when for example calling thebar3d
function(because here the array c includes nan values and the comparison operations fail).
This PR fixes this by avoiding nan in the shades array in Axes3D._shade_colors.