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
Interpret data to normalize as ndarrays #8696
Conversation
Can this as well as the #6622 fix be consolidated into |
Added logic to I also added a test. |
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.
A simple one-line change replaces everything else. I think that means #6622 can be reverted as well.
lib/matplotlib/colors.py
Outdated
result = np.ma.array(value, dtype=dtype, copy=True) | ||
return result, is_scalar | ||
result_data = np.asarray(result.data) |
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 that all you really need to do here is add the kwarg subok=False
to the np.ma.array()
line returning result
. Then result
will be a plain masked array, and result.data will be a plain ndarray, so you will not need to extract and return it here. The reason all this came up is that np.ma.array
has a surprising default of subok=True
, unlike np.array
, which has the default subok=False
.
a898d0c
to
d04261a
Compare
@efiring |
Try this substitution: # result = np.ma.array(value, dtype=dtype, copy=True)
mask = np.ma.getmask(value)
data = np.asarray(np.ma.getdata(value))
result = np.ma.array(data, mask=mask, dtype=dtype, copy=True) |
95168b2
to
590f829
Compare
Cool that works. Thanks for the suggestions, if it isn't clear I know basically nothing about masked arrays :) |
590f829
to
0f055bb
Compare
This follows on from #6622. That PR fixed the case where we were calling imshow with linear normalization. This fixes the case when we call imshow with log, symlog, or power normalization. For example:
Currently this dies with a unit error in LogNorm. Analogous to the fix applied in #6622 the fix is to interpret data handed to us by a user as an ndarray.