Skip to content

fix: handle NoNorm in format_cursor_data to prevent OverflowError#32011

Closed
mayank-dev-15 wants to merge 1 commit into
matplotlib:mainfrom
mayank-dev-15:fix-nonorm-hover
Closed

fix: handle NoNorm in format_cursor_data to prevent OverflowError#32011
mayank-dev-15 wants to merge 1 commit into
matplotlib:mainfrom
mayank-dev-15:fix-nonorm-hover

Conversation

@mayank-dev-15

Copy link
Copy Markdown

Bug

Fixes #31960

When imshow is used with uint8 data and colors.NoNorm(), mousing over the image causes an OverflowError because NoNorm.call returns the raw uint8 value unchanged, and subsequent arithmetic (
ormed * n) overflows uint8 in NumPy 2.x.

Fix

In _sig_digits_from_norm, cast
ormed to float when NoNorm is used. This prevents the uint8 overflow while preserving correct behavior for all other norms.

Reproduction

\\python
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

img = np.tile(np.arange(100, dtype=np.uint8), (100, 1))
plt.imshow(img, norm=matplotlib.colors.NoNorm())
plt.show()

Mouse over the image — OverflowError

\\

Test

Verified the fix resolves the overflow by confirming
ormed * n no longer overflows when normed is cast to float.

When imshow is used with uint8 data and colors.NoNorm(), mousing over
the image causes an OverflowError because NoNorm.__call__ returns the
raw uint8 value, and subsequent arithmetic (normed * n) overflows uint8
in NumPy 2.x which raises instead of silently wrapping.

Fix by casting normed to float when NoNorm is used, preventing the
uint8 overflow while preserving correct behavior for all other norms.

Closes matplotlib#31960
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@scottshambaugh

scottshambaugh commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Hi @mayank-dev-15, there is already a PR open for this issue, and we tend to give priority for the first fix submitted: #31967. Thank you for your contribution, but I'll close this for now.

Additionally, please use the auto-populated template when opening PRs. Yours is missing the AI disclosure section and checklist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: imshow uint8 image with colors.NoNorm() causes OverflowError when mousing over figure

2 participants