Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2896fc1

Browse filesBrowse files
authored
Merge pull request #28656 from meeseeksmachine/auto-backport-of-pr-28649-on-v3.9.x
Backport PR #28649 on branch v3.9.x (FIX: improve formatting of image values in cases of singular norms)
2 parents ecb6098 + e7aba70 commit 2896fc1
Copy full SHA for 2896fc1

File tree

3 files changed

+9
-2
lines changed
Filter options

3 files changed

+9
-2
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,9 @@ def format_cursor_data(self, data):
13461346
delta = np.diff(
13471347
self.norm.boundaries[neigh_idx:cur_idx + 2]
13481348
).max()
1349-
1349+
elif self.norm.vmin == self.norm.vmax:
1350+
# singular norms, use delta of 10% of only value
1351+
delta = np.abs(self.norm.vmin * .1)
13501352
else:
13511353
# Midpoints of neighboring color intervals.
13521354
neighbors = self.norm.inverse(

‎lib/matplotlib/cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,10 @@ def _g_sig_digits(value, delta):
22522252
it is known with an error of *delta*.
22532253
"""
22542254
if delta == 0:
2255+
if value == 0:
2256+
# if both value and delta are 0, np.spacing below returns 5e-324
2257+
# which results in rather silly results
2258+
return 3
22552259
# delta = 0 may occur when trying to format values over a tiny range;
22562260
# in that case, replace it by the distance to the closest float.
22572261
delta = abs(np.spacing(value))

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ def test_cursor_data_nonuniform(xy, data):
411411
([[.123, .987]], "[0.123]"),
412412
([[np.nan, 1, 2]], "[]"),
413413
([[1, 1+1e-15]], "[1.0000000000000000]"),
414-
([[-1, -1]], "[-1.0000000000000000]"),
414+
([[-1, -1]], "[-1.0]"),
415+
([[0, 0]], "[0.00]"),
415416
])
416417
def test_format_cursor_data(data, text):
417418
from matplotlib.backend_bases import MouseEvent

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.