Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0163d0d

Browse files
authored
Merge pull request #18812 from pmli/logformatter-coeff-edit
Change LogFormatter coeff computation
2 parents 75efe63 + b27f28f commit 0163d0d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,13 @@ def test_LogFormatter_call(self, val):
882882
temp_lf.axis = FakeAxis()
883883
assert temp_lf(val) == str(val)
884884

885+
@pytest.mark.parametrize('val', [1e-323, 2e-323, 10e-323, 11e-323])
886+
def test_LogFormatter_call_tiny(self, val):
887+
# test coeff computation in __call__
888+
temp_lf = mticker.LogFormatter()
889+
temp_lf.axis = FakeAxis()
890+
temp_lf(val)
891+
885892

886893
class TestLogitFormatter:
887894
@staticmethod

lib/matplotlib/ticker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ def __call__(self, x, pos=None):
10701070
fx = math.log(x) / math.log(b)
10711071
is_x_decade = is_close_to_int(fx)
10721072
exponent = round(fx) if is_x_decade else np.floor(fx)
1073-
coeff = round(x / b ** exponent)
1073+
coeff = round(b ** (fx - exponent))
10741074

10751075
if self.labelOnlyBase and not is_x_decade:
10761076
return ''
@@ -1154,7 +1154,7 @@ def __call__(self, x, pos=None):
11541154
fx = math.log(x) / math.log(b)
11551155
is_x_decade = is_close_to_int(fx)
11561156
exponent = round(fx) if is_x_decade else np.floor(fx)
1157-
coeff = round(x / b ** exponent)
1157+
coeff = round(b ** (fx - exponent))
11581158
if is_x_decade:
11591159
fx = round(fx)
11601160

@@ -1186,7 +1186,7 @@ def _non_decade_format(self, sign_string, base, fx, usetex):
11861186
"""Return string for non-decade locations."""
11871187
b = float(base)
11881188
exponent = math.floor(fx)
1189-
coeff = b ** fx / b ** exponent
1189+
coeff = b ** (fx - exponent)
11901190
if is_close_to_int(coeff):
11911191
coeff = round(coeff)
11921192
return r'$\mathdefault{%s%g\times%s^{%d}}$' \

0 commit comments

Comments
 (0)