Skip to content
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
4 changes: 4 additions & 0 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,10 @@ def _g_sig_digits(value, delta):
Return the number of significant digits to %g-format *value*, assuming that
it is known with an error of *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)
# 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 @@ -341,6 +341,7 @@ def test_cursor_data():
([[10001, 10000]], "[10001.000]"),
([[.123, .987]], "[0.123]"),
([[np.nan, 1, 2]], "[]"),
([[1, 1+1e-15]], "[1.0000000000000000]"),
])
def test_format_cursor_data(data, text):
from matplotlib.backend_bases import MouseEvent
Expand Down