8000 Merge pull request #23111 from anntzer/gsg · matplotlib/matplotlib@a05b6fc · GitHub
[go: up one dir, main page]

Skip to content

Commit a05b6fc

Browse files
authored
Merge pull request #23111 from anntzer/gsg
Fix _g_sig_digits for value<0 and delta=0.
2 parents b31c5ae + 6dd5b02 commit a05b6fc

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
@@ -2158,7 +2158,7 @@ def _g_sig_digits(value, delta):
21582158
if delta == 0:
21592159
# delta = 0 may occur when trying to format values over a tiny range;
21602160
# in that case, replace it by the distance to the closest float.
2161-
delta = np.spacing(value)
2161+
delta = abs(np.spacing(value))
21622162
# If e.g. value = 45.67 and delta = 0.02, then we want to round to 2 digits
21632163
# after the decimal point (floor(log10(0.02)) = -2); 45.67 contributes 2
21642164
# 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)
0