Skip to content

Fix _g_sig_digits for value<0 and delta=0. #23111

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
May 23, 2022
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
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,7 @@ def _g_sig_digits(value, delta):
if delta == 0:
# 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 = np.spacing(value)
delta = abs(np.spacing(value))
# If e.g. value = 45.67 and delta = 0.02, then we want to round to 2 digits
# after the decimal point (floor(log10(0.02)) = -2); 45.67 contributes 2
# digits before the decimal point (floor(log10(45.67)) + 1 = 2): the total
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def test_cursor_data():
([[.123, .987]], "[0.123]"),
([[np.nan, 1, 2]], "[]"),
([[1, 1+1e-15]], "[1.0000000000000000]"),
([[-1, -1]], "[-1.0000000000000000]"),
])
def test_format_cursor_data(data, text):
from matplotlib.backend_bases import MouseEvent
Expand Down