Fix format_cursor_data for values close to float resolution. #21275
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.
Previously, moving the cursor over
plt.imshow(1 + np.random.randn(10, 10) * 1e-15)
would result inValueError: math domain error
(when trying to computemath.log10(delta)
withdelta = 0
). This is because the full rangeof normalization implied by the image above (~1e-15) is representable
with float precision, but the spacing between individual colors (256x
less) is too small to be represented, and thus rounded to zero.
In general, I consider that such floating point errors should be fixed
on the user side, but this specific error seems worth fixing as the 1)
the image is still rendered correctly, 2) errors in the mouse event
handler (rendering the cursor text) are somewhat obscure for end users,
and 3) it used to work before Matplotlib 3.5.
PR Summary
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).