Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ded0a99

Browse files
authored
Merge pull request #23112 from meeseeksmachine/auto-backport-of-pr-23111-on-v3.5.x
Backport PR #23111 on branch v3.5.x (Fix _g_sig_digits for value<0 and delta=0.)
2 parents 89195ec + 5bc6769 commit ded0a99

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ def _g_sig_digits(value, delta):
21822182
if delta == 0:
21832183
# delta = 0 may occur when trying to format values over a tiny range;
21842184
# in that case, replace it by the distance to the closest float.
2185-
delta = np.spacing(value)
2185+
delta = abs(np.spacing(value))
21862186
# If e.g. value = 45.67 and delta = 0.02, then we want to round to 2 digits
21872187
# after the decimal point (floor(log10(0.02)) = -2); 45.67 contributes 2
21882188
# digits before the decimal point (floor(log10(45.67)) + 1 = 2): the total

lib/matplotlib/tests/test_image.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def test_cursor_data():
342342
([[.123, .987]], "[0.123]"),
343343
([[np.nan, 1, 2]], "[]"),
344344
([[1, 1+1e-15]], "[1.0000000000000000]"),
345+
([[-1, -1]], "[-1.0000000000000000]"),
345346
])
346347
def test_format_cursor_data(data, text):
347348
from matplotlib.backend_bases import MouseEvent

0 commit comments

Comments
 (0)