Skip to content

Commit 13b8af4

Browse files
author
Yi Wei
committed
alternative fix
fix format
1 parent 6bbe1a4 commit 13b8af4

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

lib/matplotlib/scale.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def __init__(self, axis, *, base=10, subs=None, nonpositive="clip"):
288288
def set_default_locators_and_formatters(self, axis):
289289
# docstring inherited
290290
axis.set_major_locator(LogLocator(self.base))
291-
axis.set_major_formatter(LogFormatterSciNotation(self.base))
291+
axis.set_major_formatter(LogFormatterSciNotation(self.base, labelOnlyBase=True))
292292
axis.set_minor_locator(LogLocator(self.base, self.subs))
293293
axis.set_minor_formatter(
294294
LogFormatterSciNotation(self.base,
@@ -451,7 +451,7 @@ def __init__(self, axis, *, base=10, linthresh=2, subs=None, linscale=1):
451451
def set_default_locators_and_formatters(self, axis):
452452
# docstring inherited
453453
axis.set_major_locator(SymmetricalLogLocator(self.get_transform()))
454-
axis.set_major_formatter(LogFormatterSciNotation(self.base))
454+
axis.set_major_formatter(LogFormatterSciNotation(self.base, labelOnlyBase=True))
455455
axis.set_minor_locator(SymmetricalLogLocator(self.get_transform(),
456456
self.subs))
457457
axis.set_minor_formatter(NullFormatter())

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,6 +2969,7 @@ def test_log_scales():
29692969
ax.set_yscale('log', base=5.5)
29702970
ax.invert_yaxis()
29712971
ax.set_xscale('log', base=9.0)
2972+
fmt = ax.yaxis.get_major_formatter()
29722973
xticks, yticks = [
29732974
[(t.get_loc(), t.label1.get_text()) for t in axis._update_ticks()]
29742975
for axis in [ax.xaxis, ax.yaxis]

lib/matplotlib/tests/test_ticker.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import math
21
from contextlib import nullcontext
32
import itertools
43
import locale
@@ -1142,13 +1141,13 @@ def _sub_labels(self, axis, subs=()):
11421141
label_test = [fmt(x) != '' for x in minor_tlocs]
11431142
assert label_test == label_expected
11441143

1145-
def _only_base_labels(self, axis):
1144+
def _no_minor_labels(self, axis):
11461145
fmt = axis.get_minor_formatter()
11471146
minor_tlocs = axis.get_minorticklocs()
11481147
fmt.set_locs(minor_tlocs)
11491148
fxs = np.log(minor_tlocs)/np.log(10)
1150-
label_expected = [math.isclose(fx, round(fx)) for fx in fxs]
1151-
label_test = [fmt(x) != '' for x in minor_tlocs]
1149+
label_expected = [True] * len(fxs)
1150+
label_test = [fmt(x) == '' for x in minor_tlocs]
11521151
assert label_test == label_expected
11531152

11541153
@mpl.style.context('default')
@@ -1196,7 +1195,7 @@ def test_sublabel(self):
11961195
minor_thresholds=(0, 0)
11971196
)
11981197
)
1199-
self._only_base_labels(ax.xaxis)
1198+
self._no_minor_labels(ax.xaxis)
12001199

12011200
@pytest.mark.parametrize('val', [1, 10, 100, 1000])
12021201
def test_LogFormatter_call(self, val):

lib/matplotlib/ticker.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ def set_locs(self, locs=None):
949949
numdec = abs(vmax - vmin)
950950

951951
if numdec > self.minor_thresholds[0]:
952-
# Label only bases
952+
# No minor ticks will be labeled
953953
self._sublabels = {}
954954
elif numdec > self.minor_thresholds[1]:
955955
# Add labels between bases at log-spaced coefficients;
@@ -985,7 +985,7 @@ def __call__(self, x, pos=None):
985985
coeff = round(b ** (fx - exponent))
986986

987987
# Label only bases
988-
if self.labelOnlyBase or self._sublabels == {}:
988+
if self.labelOnlyBase:
989989
if not is_x_decade:
990990
return ''
991991
elif self._sublabels is not None and coeff not in self._sublabels:
@@ -1072,8 +1072,7 @@ def __call__(self, x, pos=None):
10721072
if is_x_decade:
10731073
fx = round(fx)
10741074

1075-
# Label only bases
1076-
if self.labelOnlyBase or self._sublabels == {}:
1075+
if self.labelOnlyBase:
10771076
if not is_x_decade:
10781077
return ''
10791078
elif self._sublabels is not None and coeff not in self._sublabels:

0 commit comments

Comments
 (0)