8000 Fix 999.9... edge case in ticker.EngFormatter for negative numbers by Lewn · Pull Request #12045 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix 999.9... edge case in ticker.EngFormatter for negative numbers #12045

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 4 commits into from
Sep 7, 2018
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
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ class TestEngFormatter(object):
(1.23456789, ('1.23457', '1', '1.23')),
(999.9, ('999.9', '1 k', '999.90')), # places=0: corner-case rounding
(999.9999, ('1 k', '1 k', '1.00 k')), # corner-case roudning for all
(-999.9999, ('-1 k', '-1 k', '-1.00 k')), # negative corner-case
(1000, ('1 k', '1 k', '1.00 k')),
(1001, ('1.001 k', '1 k', '1.00 k')),
(100001, ('100.001 k', '100 k', '100.00 k')),
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,8 @@ def format_eng(self, num):
# Taking care of the cases like 999.9..., which may be rounded to 1000
# instead of 1 k. Beware of the corner case of values that are beyond
# the range of SI prefixes (i.e. > 'Y').
if float(format(mant, fmt)) >= 1000 and pow10 < max(self.ENG_PREFIXES):
if (abs(float(format(mant, fmt))) >= 1000
and pow10 < max(self.ENG_PREFIXES)):
mant /= 1000
pow10 += 3

Expand Down
0