Skip to content
Merged
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
6 changes: 4 additions & 2 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,9 @@ 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*.
"""
# For inf or nan, the precision doesn't matter.
if not math.isfinite(value):
return 0
if delta == 0:
if value == 0:
# if both value and delta are 0, np.spacing below returns 5e-324
Expand All @@ -2221,11 +2224,10 @@ def _g_sig_digits(value, delta):
# digits before the decimal point (floor(log10(45.67)) + 1 = 2): the total
# is 4 significant digits. A value of 0 contributes 1 "digit" before the
# decimal point.
# For inf or nan, the precision doesn't matter.
return max(
0,
(math.floor(math.log10(abs(value))) + 1 if value else 1)
- math.floor(math.log10(delta))) if math.isfinite(value) else 0
- math.floor(math.log10(delta)))


def _unikey_or_keysym_to_mplkey(unikey, keysym):
Expand Down
Loading