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

Skip to content

Commit 3227ed1

Browse files
committed
BUG: Duplicated test class in test_ticker.py
1 parent 7d0a3d3 commit 3227ed1

File tree

1 file changed

+48
-50
lines changed

1 file changed

+48
-50
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -239,56 +239,6 @@ def test_use_offset(self, use_offset):
239239
assert use_offset == tmp_form.get_useOffset()
240240

241241

242-
class TestLogFormatter(object):
243-
def _sub_labels(self, axis, subs=()):
244-
"Test whether locator marks subs to be labeled"
245-
fmt = axis.get_minor_formatter()
246-
minor_tlocs = axis.get_minorticklocs()
247-
fmt.set_locs(minor_tlocs)
248-
coefs = minor_tlocs / 10**(np.floor(np.log10(minor_tlocs)))
249-
label_expected = [np.round(c) in subs for c in coefs]
250-
label_test = [fmt(x) != '' for x in minor_tlocs]
251-
assert label_test == label_expected
252-
253-
@pytest.mark.style('default')
254-
def test_sublabel(self):
255-
# test label locator
256-
fig, ax = plt.subplots()
257-
ax.set_xscale('log')
258-
ax.xaxis.set_major_locator(mticker.LogLocator(base=10, subs=[]))
259-
ax.xaxis.set_minor_locator(mticker.LogLocator(base=10,
260-
subs=np.arange(2, 10)))
261-
ax.xaxis.set_major_formatter(mticker.LogFormatter(labelOnlyBase=True))
262-
ax.xaxis.set_minor_formatter(mticker.LogFormatter(labelOnlyBase=False))
263-
# axis range above 3 decades, only bases are labeled
264-
ax.set_xlim(1, 1e4)
265-
fmt = ax.xaxis.get_major_formatter()
266-
fmt.set_locs(ax.xaxis.get_majorticklocs())
267-
show_major_labels = [fmt(x) != ''
268-
for x in ax.xaxis.get_majorticklocs()]
269-
assert np.all(show_major_labels)
270-
self._sub_labels(ax.xaxis, subs=[])
271-
272-
# For the next two, if the numdec threshold in LogFormatter.set_locs
273-
# were 3, then the label sub would be 3 for 2-3 decades and (2,5)
274-
# for 1-2 decades. With a threshold of 1, subs are not labeled.
275-
# axis range at 2 to 3 decades
276-
ax.set_xlim(1, 800)
277-
self._sub_labels(ax.xaxis, subs=[])
278-
279-
# axis range at 1 to 2 decades
280-
ax.set_xlim(1, 80)
281-
self._sub_labels(ax.xaxis, subs=[])
282-
283-
# axis range at 0.4 to 1 decades, label subs 2, 3, 4, 6
284-
ax.set_xlim(1, 8)
285-
self._sub_labels(ax.xaxis, subs=[2, 3, 4, 6])
286-
287-
# axis range at 0 to 0.4 decades, label all
288-
ax.set_xlim(0.5, 0.9)
289-
self._sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))
290-
291-
292242
class FakeAxis(object):
293243
"""Allow Formatter to be called without having a "full" plot set up."""
294244
def __init__(self, vmin=1, vmax=10):
@@ -503,6 +453,54 @@ def test_pprint(self, value, domain, expected):
503453
label = fmt.pprint_val(value, domain)
504454
assert label == expected
505455

456+
def _sub_labels(self, axis, subs=()):
457+
"Test whether locator marks subs to be labeled"
458+
fmt = axis.get_minor_formatter()
459+
minor_tlocs = axis.get_minorticklocs()
460+
fmt.set_locs(minor_tlocs)
461+
coefs = minor_tlocs / 10**(np.floor(np.log10(minor_tlocs)))
462+
label_expected = [np.round(c) in subs for c in coefs]
463+
label_test = [fmt(x) != '' for x in minor_tlocs]
464+
assert label_test == label_expected
465+
466+
@pytest.mark.style('default')
467+
def test_sublabel(self):
468+
# test label locator
469+
fig, ax = plt.subplots()
470+
ax.set_xscale('log')
471+
ax.xaxis.set_major_locator(mticker.LogLocator(base=10, subs=[]))
472+
ax.xaxis.set_minor_locator(mticker.LogLocator(base=10,
473+
subs=np.arange(2, 10)))
474+
ax.xaxis.set_major_formatter(mticker.LogFormatter(labelOnlyBase=True))
475+
ax.xaxis.set_minor_formatter(mticker.LogFormatter(labelOnlyBase=False))
476+
# axis range above 3 decades, only bases are labeled
477+
ax.set_xlim(1, 1e4)
478+
fmt = ax.xaxis.get_major_formatter()
479+
fmt.set_locs(ax.xaxis.get_majorticklocs())
480+
show_major_labels = [fmt(x) != ''
481+
for x in ax.xaxis.get_majorticklocs()]
482+
assert np.all(show_major_labels)
483+
self._sub_labels(ax.xaxis, subs=[])
484+
485+
# For the next two, if the numdec threshold in LogFormatter.set_locs
486+
# were 3, then the label sub would be 3 for 2-3 decades and (2,5)
487+
# for 1-2 decades. With a threshold of 1, subs are not labeled.
488+
# axis range at 2 to 3 decades
489+
ax.set_xlim(1, 800)
490+
self._sub_labels(ax.xaxis, subs=[])
491+
492+
# axis range at 1 to 2 decades
493+
ax.set_xlim(1, 80)
494+
self._sub_labels(ax.xaxis, subs=[])
495+
496+
# axis range at 0.4 to 1 decades, label subs 2, 3, 4, 6
497+
ax.set_xlim(1, 8)
498+
self._sub_labels(ax.xaxis, subs=[2, 3, 4, 6])
499+
500+
# axis range at 0 to 0.4 decades, label all
501+
ax.set_xlim(0.5, 0.9)
502+
self._sub_labels(ax.xaxis, subs=np.arange(2, 10, dtype=int))
503+
506504

507505
class TestFormatStrFormatter(object):
508506
def test_basic(self):

0 commit comments

Comments
 (0)