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

Skip to content

Commit 74c2e7c

Browse files
committed
Deprecate ticker.Base.
1 parent 2b40260 commit 74c2e7c

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def test_set_params(self):
6666
"""
6767
mult = mticker.MultipleLocator(base=0.7)
6868
mult.set_params(base=1.7)
69-
assert mult._base == 1.7
69+
assert mult._edge.step == 1.7
7070

7171

7272
class TestAutoMinorLocator(object):

lib/matplotlib/ticker.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,12 +1661,12 @@ def view_limits(self, vmin, vmax):
16611661
return mtransforms.nonsingular(vmin, vmax)
16621662

16631663

1664-
# @cbook.deprecated("3.1")
1664+
@cbook.deprecated("3.1")
16651665
def closeto(x, y):
16661666
return abs(x - y) < 1e-10
16671667

16681668

1669-
# @cbook.deprecated("3.1")
1669+
@cbook.deprecated("3.1")
16701670
class Base(object):
16711671
'this solution has some hacks to deal with floating point inaccuracies'
16721672
def __init__(self, base):
@@ -1710,17 +1710,16 @@ def get_base(self):
17101710

17111711
class MultipleLocator(Locator):
17121712
"""
1713-
Set a tick on every integer that is multiple of base in the
1714-
view interval
1713+
Set a tick on each integer multiple of a base within the view interval.
17151714
"""
17161715

17171716
def __init__(self, base=1.0):
1718-
self._base = Base(base)
1717+
self._edge = _Edge_integer(base, 0)
17191718

17201719
def set_params(self, base):
17211720
"""Set parameters within this locator."""
17221721
if base is not None:
1723-
self._base = base
1722+
self._edge = _Edge_integer(base, 0)
17241723

17251724
def __call__(self):
17261725
'Return the locations of the ticks'
@@ -1730,20 +1729,20 @@ def __call__(self):
17301729
def tick_values(self, vmin, vmax):
17311730
if vmax < vmin:
17321731
vmin, vmax = vmax, vmin
1733-
vmin = self._base.ge(vmin)
1734-
base = self._base.get_base()
1735-
n = (vmax - vmin + 0.001 * base) // base
1736-
locs = vmin - base + np.arange(n + 3) * base
1732+
step = self._edge.step
1733+
vmin = self._edge.ge(vmin) * step
1734+
n = (vmax - vmin + 0.001 * step) // step
1735+
locs = vmin - step + np.arange(n + 3) * step
17371736
return self.raise_if_exceeds(locs)
17381737

17391738
def view_limits(self, dmin, dmax):
17401739
"""
17411740
Set the view limits to the nearest multiples of base that
1742-
contain the data
1741+
contain the data.
17431742
"""
17441743
if rcParams['axes.autolimit_mode'] == 'round_numbers':
1745-
vmin = self._base.le(dmin)
1746-
vmax = self._base.ge(dmax)
1744+
vmin = self._edge.le(dmin) * self._edge.step
1745+
vmax = self._base.ge(dmax) * self._edge.step
17471746
if vmin == vmax:
17481747
vmin -= 1
17491748
vmax += 1
@@ -1767,7 +1766,7 @@ def scale_range(vmin, vmax, n=1, threshold=100):
17671766

17681767
class _Edge_integer:
17691768
"""
1770-
Helper for MaxNLocator.
1769+
Helper for MaxNLocator, MultipleLocator, etc.
17711770
17721771
Take floating point precision limitations into account when calculating
17731772
tick locations as integer multiples of a step.
@@ -1794,14 +1793,14 @@ def closeto(self, ms, edge):
17941793
return abs(ms - edge) < tol
17951794

17961795
def le(self, x):
1797-
'Return the largest n: n*base <= x'
1796+
'Return the largest n: n*step <= x.'
17981797
d, m = _divmod(x, self.step)
17991798
if self.closeto(m / self.step, 1):
18001799
return (d + 1)
18011800
return d
18021801

18031802
def ge(self, x):
1804-
'Return the smallest n: n*base >= x'
1803+
'Return the smallest n: n*step >= x.'
18051804
d, m = _divmod(x, self.step)
18061805
if self.closeto(m / self.step, 0):
18071806
return d

0 commit comments

Comments
 (0)