-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: resolution of imshow for floats and 2-D greyscale PIL images #10613
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
Conversation
lib/matplotlib/image.py
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these newmax/newmin appropriate if LogNorm
or something similarly non-linear is being used?
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
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_data
so 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