Fix px.imshow ignoring zmin/zmax when the image contains NaN - #5778
Open
MohammadHijjawi97 wants to merge 1 commit into
Open
MohammadHijjawi97 wants to merge 1 commit into
MohammadHijjawi97 wants to merge 1 commit into
Conversation
When only one of zmin/zmax was passed (or binary_string was used) with contrast_rescaling="minmax", the missing bound was computed with img.min()/img.max(), which return NaN if the image contains NaN values. The resulting NaN cmin/cmax made the color range fall back to autoscaling, so the user-provided bound was ignored. Use np.nanmin/np.nanmax instead. Fixes plotly#4299
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Closes #4299
Description of change
When only one of
zmin/zmaxis passed topx.imshow(orbinary_string=Trueis used) with min/max contrast rescaling, the missing bound was computed withimg.min()/img.max(), which return NaN if the image contains NaN values. The resulting NaNcmin/cmaxmade the user-provided bound have no effect. This usesnp.nanmin/np.nanmaxinstead so NaN values are ignored.Demo
Testing strategy
Added
test_zmin_zmax_nan_dataintests/test_optional/test_px/test_imshow.py, which checks that passing onlyzmaxor onlyzminon an image containing NaN produces the expectedcmin/cmax. It fails without the fix and passes with it; the rest oftest_imshow.pyis unchanged by this PR (on Windows,test_imshow_source_dtype_zmax[infer-int32]fails both before and after, in a branch this doesn't touch).Guidelines