Skip to content

Navigation Menu

Sign in
Appearance settings

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 6dd5b02

Browse filesBrowse files
committed
Fix _g_sig_digits for value<0 and delta=0.
np.spacing can return negative values, so we need an abs().
1 parent b31c5ae commit 6dd5b02
Copy full SHA for 6dd5b02

File tree

Expand file treeCollapse file tree

2 files changed

+2
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+2
-1
lines changed

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.