Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Better choice of offset-text.#5785
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -180,6 +180,8 @@ def check_offset_for(left, right, offset): | ||
| (-100000.5, -99990.5, -100000), | ||
| (1233999, 1234001, 1234000), | ||
| (-1234001, -1233999, -1234000), | ||
| (1, 1, 0), | ||
| (123, 123, 123), | ||
| # Test cases courtesy of @WeatherGod | ||
| (.4538, .4578, .45), | ||
| (3789.12, 3783.1, 3780), | ||
| @@ -201,6 +203,7 @@ def check_offset_for(left, right, offset): | ||
| for left, right, offset in test_data: | ||
| yield check_offset_for, left, right, offset | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ithink all but two test cases are ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't really think I need to support left == right because I don't see how this can ever happen. Other issues handled in new (rebased) commit. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Well, your code does check for the ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Sure. I'll wait for#6022 to be merged in so that the tests are actuall run. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. updated. | ||
| yield check_offset_for, right, left, offset | ||
| def _logfe_helper(formatter, base, locs, i, expected_result): | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -164,6 +164,7 @@ | ||
| from matplotlib.externals import six | ||
| import decimal | ||
| import itertools | ||
| import locale | ||
| import math | ||
| import numpy as np | ||
| @@ -680,36 +681,29 @@ def _compute_offset(self): | ||
| self.offset = 0 | ||
| return | ||
| lmin, lmax = locs.min(), locs.max() | ||
| # Only use offset if there are at least two ticks and every tick has | ||
| # the same sign. | ||
| if lmin == lmax or lmin <= 0 <= lmax: | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Can move this section above the absolute values to short-circuit a little earlier. | ||
| self.offset = 0 | ||
| return | ||
| # min, max comparing absolute values (we want division to round towards | ||
| # zero so we work on absolute values). | ||
| abs_min, abs_max = sorted([abs(float(lmin)), abs(float(lmax))]) | ||
| sign = math.copysign(1, lmin) | ||
| # What is the smallest power of ten such that abs_min and abs_max are | ||
| # equal up to that precision? | ||
| # Note: Internally using oom instead of 10 ** oom avoids some numerical | ||
| # accuracy issues. | ||
| oom_max = math.ceil(math.log10(abs_max)) | ||
| oom = 1 + next(oom for oom in itertools.count(oom_max, -1) | ||
| if abs_min // 10 ** oom != abs_max // 10 ** oom) | ||
| if (abs_max - abs_min) / 10 ** oom <= 1e-2: | ||
| # Handle the case of straddling a multiple of a large power of ten | ||
| # (relative to the span). | ||
| # What is the smallest power of ten such that abs_min and abs_max | ||
| # are no more than 1 apart at that precision? | ||
| oom = 1 + next(oom for oom in itertools.count(oom_max, -1) | ||
| if abs_max // 10 ** oom - abs_min // 10 ** oom > 1) | ||
| # Only use offset if it saves at least two significant digits. | ||
| self.offset = (sign * (abs_max // 10 ** oom) * 10 ** oom | ||
| if abs_max // 10 ** oom >= 10 | ||