Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite06b857

Browse files
author
Yi Wei
committed
alternative fix
fix formatremove irrelevant code
1 parent6bbe1a4 commite06b857

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
defset_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
defset_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-
importmath
21
fromcontextlibimportnullcontext
32
importitertools
43
importlocale
@@ -1142,13 +1141,12 @@ def _sub_labels(self, axis, subs=()):
11421141
label_test= [fmt(x)!=''forxinminor_tlocs]
11431142
assertlabel_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))forfxinfxs]
1151-
label_test= [fmt(x)!=''forxinminor_tlocs]
1148+
label_expected= [True]*len(minor_tlocs)
1149+
label_test= [fmt(x)==''forxinminor_tlocs]
11521150
assertlabel_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
deftest_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
ifnumdec>self.minor_thresholds[0]:
952-
#Label only bases
952+
#No minor ticks will be labeled
953953
self._sublabels= {}
954954
elifnumdec>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)ifis_x_decadeelsenp.floor(fx)
985985
coeff=round(b** (fx-exponent))
986986

987-
# Label only bases
988-
ifself.labelOnlyBaseorself._sublabels== {}:
987+
ifself.labelOnlyBase:
989988
ifnotis_x_decade:
990989
return''
991990
elifself._sublabelsisnotNoneandcoeffnotinself._sublabels:
@@ -1072,8 +1071,7 @@ def __call__(self, x, pos=None):
10721071
ifis_x_decade:
10731072
fx=round(fx)
10741073

1075-
# Label only bases
1076-
ifself.labelOnlyBaseorself._sublabels== {}:
1074+
ifself.labelOnlyBase:
10771075
ifnotis_x_decade:
10781076
return''
10791077
elifself._sublabelsisnotNoneandcoeffnotinself._sublabels:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp