8000 Factor out common formats strings in LogFormatter, LogFormatterExponent. by anntzer · Pull Request #29053 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Factor out common formats strings in LogFormatter, LogFormatterExponent. #29053

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 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,7 @@ def set_locs(self, locs=None):
self._sublabels = set(np.arange(1, b + 1))

def _num_to_string(self, x, vmin, vmax):
if x > 10000:
s = '%1.0e' % x
elif x < 1:
s = '%1.0e' % x
else:
s = self._pprint_val(x, vmax - vmin)
return s
return self._pprint_val(x, vmax - vmin) if 1 <= x <= 10000 else f"{x:1.0e}"

def __call__(self, x, pos=None):
# docstring inherited
Expand Down Expand Up @@ -1053,15 +1047,14 @@ class LogFormatterExponent(LogFormatter):
"""
Format values for log axis using ``exponent = log_base(value)``.
"""

def _num_to_string(self, x, vmin, vmax):
fx = math.log(x) / math.log(self._base)
if abs(fx) > 10000:
s = '%1.0g' % fx
elif abs(fx) < 1:
s = '%1.0g' % fx
else:
if 1 <= abs(fx) <= 10000:
fd = math.log(vmax - vmin) / math.log(self._base)
s = self._pprint_val(fx, fd)
else:
s = f"{fx:1.0g}"
return s


Expand Down
Loading
0