FIX: resolution of imshow for floats and 2-D greyscale PIL images#10613
Conversation
| if newmin > a_min: | ||
| A_scaled[A_scaled < newmin ] = newmin | ||
| a_min = np.float64(newmin) | ||
| newmax = vmid + dv * 1.e7 |
There was a problem hiding this comment.
Are these newmax/newmin appropriate if LogNorm or something similarly non-linear is being used?
There was a problem hiding this comment.
Grrrrr, not sure. Probably not!
Of course, the way the interpolation is done is questionable if you use LogNorm. Right now we are doing the interpolation in data space instead of normed-space. It seems the latter is more appropriate for non-linear norms. ping @tacaswell
There was a problem hiding this comment.
can we use np.clip here?
Do we actually have to do this indexing step or can we reset a_min and a_max and let Agg deal with the clipping to [0, 1] internally?
There was a problem hiding this comment.
To be clear, I'm not saying we shouldn't take your approach--just wondering if a check is in order.
There was a problem hiding this comment.
In LogNorm vmin and vmax are in data space, not the log of the data, so it should work fine for LogNorm. Not sure about all the other norms.
There was a problem hiding this comment.
The norms all work with vmin and vmax in data space (rather than transformed space), so this fix is fine. I've uploaded a version that uses np.clip instead of indexing.
@tacaswell we indeed need to clip right away - not clipping is the whole problem with the floating point math of the next step.
efiring
left a comment
There was a problem hiding this comment.
Both parts of this look good to me. My initial suggestion regarding handling the jpeg problem was clearly wrong, as I suspected it might be.
|
Thanks @jklymak ! |
Backport PR #10613 on branch v2.2.x
PR Summary
Addresses big values in floating point arrays losing precision (#10567)
We discussed on the call including a warning. But I'm still not sure why this is required because this doesn't touch the original data, just the scaled data (before it is scaled).
New test is added. Before the change the test code would yield:
After:
EDIT: Added a fix for #10616 when an image from PIL is 2-D this converts to RGBA in
set_dataso it is rendered in greyscale.This needs a test.Also needs some approval that this is the correct route. @efiring thought we should just cast to a 2-D masked array, but that will go through the norm and colormap route, and would therefore not plot as greyscale.PR Checklist