8000 Merge pull request #29053 from anntzer/lf · matplotlib/matplotlib@3f2cc0b · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f2cc0b

Browse files
authored
Merge pull request #29053 from anntzer/lf
Factor out common formats strings in LogFormatter, LogFormatterExponent.
2 parents 32ec60d + 6c92776 commit 3f2cc0b

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
@@ -1001,13 +1001,7 @@ def set_locs(self, locs=None):
10011001
self._sublabels = set(np.arange(1, b + 1))
10021002

10031003
def _num_to_string(self, x, vmin, vmax):
1004-
if x > 10000:
1005-
s = '%1.0e' % x
1006-
elif x < 1:
1007-
s = '%1.0e' % x
1008-
else:
1009-
s = self._pprint_val(x, vmax - vmin)
1010-
return s
1004+
return self._pprint_val(x, vmax - vmin) if 1 <= x <= 10000 else f"{x:1.0e}"
10111005

10121006
def __call__(self, x, pos=None):
10131007
# docstring inherited
@@ -1067,15 +1061,14 @@ class LogFormatterExponent(LogFormatter):
10671061
"""
10681062
Format values for log axis using ``exponent = log_base(value)``.
10691063
"""
1064+
10701065
def _num_to_string(self, x, vmin, vmax):
10711066
fx = math.log(x) / math.log(self._base)
1072-
if abs(fx) > 10000:
1073-
s = '%1.0g' % fx
1074-
elif abs(fx) < 1:
1075-
s = '%1.0g' % fx
1076-
else:
1067+
if 1 <= abs(fx) <= 10000:
10771068
fd = math.log(vmax - vmin) / math.log(self._base)
10781069
s = self._pprint_val(fx, fd)
1070+
else:
1071+
s = f"{fx:1.0g}"
10791072
return s
10801073

10811074

0 commit comments

Comments
 (0)
0