8000 Merge pull request #12045 from Lewn/patch-1 · matplotlib/matplotlib@0753e59 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0753e59

Browse files
authored
Merge pull request #12045 from Lewn/patch-1
Fix 999.9... edge case in ticker.EngFormatter for negative numbers
2 parents 3669591 + e3ba6ba commit 0753e59

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ class TestEngFormatter(object):
655655
(1.23456789, ('1.23457', '1', '1.23')),
656656
(999.9, ('999.9', '1 k', '999.90')), # places=0: corner-case rounding
657657
(999.9999, ('1 k', '1 k', '1.00 k')), # corner-case roudning for all
658+
(-999.9999, ('-1 k', '-1 k', '-1.00 k')), # negative corner-case
658659
(1000, ('1 k', '1 k', '1.00 k')),
659660
(1001, ('1.001 k', '1 k', '1.00 k')),
660661
(100001, ('100.001 k', '100 k', '100.00 k')),

lib/matplotlib/ticker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,8 @@ def format_eng(self, num):
12681268
# Taking care of the cases like 999.9..., which may be rounded to 1000
12691269
# instead of 1 k. Beware of the corner case of values that are beyond
12701270
# the range of SI prefixes (i.e. > 'Y').
1271-
if float(format(mant, fmt)) >= 1000 and pow10 < max(self.ENG_PREFIXES):
1271+
if (abs(float(format(mant, fmt))) >= 1000
1272+
and pow10 < max(self.ENG_PREFIXES)):
12721273
mant /= 1000
12731274
pow10 += 3
12741275

0 commit comments

Comments
 (0)
0