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

Commit6c92776

Browse files
committed
Factor out common formats strings in LogFormatter, LogFormatterExponent.
The x < 1 and x > 10000 branches can come together.
1 parent202a277 commit6c92776

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

‎lib/matplotlib/ticker.py‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -987,13 +987,7 @@ def set_locs(self, locs=None):
987987
self._sublabels=set(np.arange(1,b+1))
988988

989989
def_num_to_string(self,x,vmin,vmax):
990-
ifx>10000:
991-
s='%1.0e'%x
992-
elifx<1:
993-
s='%1.0e'%x
994-
else:
995-
s=self._pprint_val(x,vmax-vmin)
996-
returns
990+
returnself._pprint_val(x,vmax-vmin)if1<=x<=10000elsef"{x:1.0e}"
997991

998992
def__call__(self,x,pos=None):
999993
# docstring inherited
@@ -1053,15 +1047,14 @@ class LogFormatterExponent(LogFormatter):
10531047
"""
10541048
Format values for log axis using ``exponent = log_base(value)``.
10551049
"""
1050+
10561051
def_num_to_string(self,x,vmin,vmax):
10571052
fx=math.log(x)/math.log(self._base)
1058-
ifabs(fx)>10000:
1059-
s='%1.0g'%fx
1060-
elifabs(fx)<1:
1061-
s='%1.0g'%fx
1062-
else:
1053+
if1<=abs(fx)<=10000:
10631054
fd=math.log(vmax-vmin)/math.log(self._base)
10641055
s=self._pprint_val(fx,fd)
1056+
else:
1057+
s=f"{fx:1.0g}"
10651058
returns
10661059

10671060

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp