-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Slightly more efficient impl.; more tests.
- Loading branch information
commit 0c39a78b040e00caf87eee41d448a5e32c26cf54
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
# 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))]) | ||
# Only use offset if there are at least two ticks and every tick has | ||
# the same sign. | ||
if lmin == lmax or lmin <= 0 <= lmax: | ||
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 = math.ceil(math.log10(abs_max)) | ||
while True: | ||
if abs_min // 10 ** oom != abs_max // 10 ** oom: | ||
oom += 1 | ||
break | ||
oom -= 1 | ||
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 | ||
# at most 1 apart? | ||
oom = math.ceil(math.log10(abs_max)) | ||
while True: | ||
if abs_max // 10 ** oom - abs_min // 10 ** oom > 1: | ||
oom += 1 | ||
break | ||
oom -= 1 | ||
# 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all but two test cases are
left < right
; would it also make sense to yield in the reverse order? Also, I don't think there are any tests forleft == right
(though I don't see why that won't work correctly.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, your code does check for the
left == right
case, so it's good so codify what the expected behaviour is in that case. I think the default locators would avoid this situation, but I'm not sure about user-created locators.There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.