8000 alternative fix · matplotlib/matplotlib@e06b857 · GitHub
[go: up one dir, main page]

Skip to content

Commit e06b857

Browse files
author
Yi Wei
committed
alternative fix
fix format remove irrelevant code
1 parent 6bbe1a4 commit e06b857

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
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_ticker.py

Lines changed: 5 additions & 7 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,12 @@ 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)
1149-
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]
1148+
label_expected = [True] * len(minor_tlocs)
1149+
label_test = [fmt(x) == '' for x in minor_tlocs]
11521150
assert label_test == label_expected
11531151

11541152
@mpl.style.context('default')
@@ -1189,14 +1187,14 @@ def test_sublabel(self):
11891187
ax.set_xlim(0.5, 0.9)
11901188
self._sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))
11911189

1192-
# minor_thresholds=(0, 0), label only bases
1190+
# minor_thresholds=(0, 0), no minor tick will be labeled
11931191
ax.xaxis.set_minor_formatter(
11941192
mticker.LogFormatter(
11951193
labelOnlyBase=False,
11961194
minor_thresholds=(0, 0)
11971195
)
11981196
)
1199-
self._only_base_labels(ax.xaxis)
1197+
self._no_minor_labels(ax.xaxis)
12001198

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

lib/matplotlib/ticker.py

Lines changed: 3 additions & 5 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;
@@ -984,8 +984,7 @@ def __call__(self, x, pos=None):
984984
exponent = round(fx) if is_x_decade else np.floor(fx)
985985
coeff = round(b ** (fx - exponent))
986986

987-
# Label only bases
988-
if self.labelOnlyBase or self._sublabels == {}:
987+
if self.labelOnlyBase:
989988
if not is_x_decade:
990989
return ''
991990
elif self._sublabels is not None and coeff not in self._sublabels:
@@ -1072,8 +1071,7 @@ def __call__(self, x, pos=None):
10721071
if is_x_decade:
10731072
fx = round(fx)
10741073

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

0 commit comments

Comments
 (0)
0