8000 FIX: improve formatting of image values in cases of singular norms by tacaswell · Pull Request #28649 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: improve formatting of image values in cases of singular norms #28649

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

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,9 @@ def format_cursor_data(self, data):
delta = np.diff(
self.norm.boundaries[neigh_idx:cur_idx + 2]
).max()

elif self.norm.vmin == self.norm.vmax:
# singular norms, use delta of 10% of only value
delta = np.abs(self.norm.vmin * .1)
else:
# Midpoints of neighboring color intervals.
neighbors = self.norm.inverse(
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,10 @@ def _g_sig_digits(value, delta):
it is known with an error of *delta*.
"""
if delta == 0:
if value == 0:
# if both value and delta are 0, np.spacing below returns 5e-324
# which results in rather silly results
return 3
# delta = 0 may occur when trying to format values over a tiny range;
# in that case, replace it by the distance to the closest float.
delta = abs(np.spacing(value))
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ def test_cursor_data_nonuniform(xy, data):
([[.123, .987]], "[0.123]"),
([[np.nan, 1, 2]], "[]"),
([[1, 1+1e-15]], "[1.0000000000000000]"),
([[-1, -1]], "[-1.0000000000000000]"),
([[-1, -1]], "[-1.0]"),
([[0, 0]], "[0.00]"),
])
def test_format_cursor_data(data, text):
from matplotlib.backend_bases import MouseEvent
Expand Down
Loading
0