Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39efb99

Browse files
committed
Slightly more efficient impl.; more tests.
1 parent5726980 commit39efb99

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

‎lib/matplotlib/tests/test_ticker.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def check_offset_for(left, right, offset):
201201

202202
forleft,right,offsetintest_data:
203203
yieldcheck_offset_for,left,right,offset
204+
yieldcheck_offset_for,right,left,offset
204205

205206

206207
def_logfe_helper(formatter,base,locs,i,expected_result):

‎lib/matplotlib/ticker.py‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
frommatplotlib.externalsimportsix
156156

157157
importdecimal
158+
importitertools
158159
importlocale
159160
importmath
160161
importnumpyasnp
@@ -565,36 +566,29 @@ def _compute_offset(self):
565566
self.offset=0
566567
return
567568
lmin,lmax=locs.min(),locs.max()
568-
# min, max comparing absolute values (we want division to round towards
569-
# zero so we work on absolute values).
570-
abs_min,abs_max=sorted([abs(float(lmin)),abs(float(lmax))])
571569
# Only use offset if there are at least two ticks and every tick has
572570
# the same sign.
573571
iflmin==lmaxorlmin<=0<=lmax:
574572
self.offset=0
575573
return
574+
# min, max comparing absolute values (we want division to round towards
575+
# zero so we work on absolute values).
576+
abs_min,abs_max=sorted([abs(float(lmin)),abs(float(lmax))])
576577
sign=math.copysign(1,lmin)
577578
# What is the smallest power of ten such that abs_min and abs_max are
578579
# equal up to that precision?
579580
# Note: Internally using oom instead of 10 ** oom avoids some numerical
580581
# accuracy issues.
581-
oom=math.ceil(math.log10(abs_max))
582-
whileTrue:
583-
ifabs_min//10**oom!=abs_max//10**oom:
584-
oom+=1
585-
break
586-
oom-=1
582+
oom_max=math.ceil(math.log10(abs_max))
583+
oom=1+next(oomforoominitertools.count(oom_max,-1)
584+
ifabs_min//10**oom!=abs_max//10**oom)
587585
if (abs_max-abs_min)/10**oom<=1e-2:
588586
# Handle the case of straddling a multiple of a large power of ten
589587
# (relative to the span).
590588
# What is the smallest power of ten such that abs_min and abs_max
591-
# at most 1 apart?
592-
oom=math.ceil(math.log10(abs_max))
593-
whileTrue:
594-
ifabs_max//10**oom-abs_min//10**oom>1:
595-
oom+=1
596-
break
597-
oom-=1
589+
# are no more than 1 apart at that precision?
590+
oom=1+next(oomforoominitertools.count(oom_max,-1)
591+
ifabs_max//10**oom-abs_min//10**oom>1)
598592
# Only use offset if it saves at least two significant digits.
599593
self.offset= (sign* (abs_max//10**oom)*10**oom
600594
ifabs_max//10**oom>=10

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp