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

Skip to content

Commit af930ce

Browse files
committed
Deprecate MAXTICKS, Locator.raise_if_exceeds.
1 parent 91a2bb8 commit af930ce

File tree

3 files changed

+15
-38
lines changed

3 files changed

+15
-38
lines changed

lib/matplotlib/dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ def tick_values(self, vmin, vmax):
821821
dates = self.rule.between(vmin, vmax, True)
822822
if len(dates) == 0:
823823
return date2num([vmin, vmax])
824-
return self.raise_if_exceeds(date2num(dates))
824+
return date2num(dates)
825825

826826
def _get_unit(self):
827827
"""

lib/matplotlib/tests/test_dates.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,6 @@ def test_date_axvline():
8888
fig.autofmt_xdate()
8989

9090

91-
def test_too_many_date_ticks():
92-
# Attempt to test SF 2715172, see
93-
# https://sourceforge.net/tracker/?func=detail&aid=2715172&group_id=80706&atid=560720
94-
# setting equal datetimes triggers and expander call in
95-
# transforms.nonsingular which results in too many ticks in the
96-
# DayLocator. This should trigger a Locator.MAXTICKS RuntimeError
97-
warnings.filterwarnings(
98-
'ignore',
99-
'Attempting to set identical left==right results\\nin singular '
100-
'transformations; automatically expanding.\\nleft=\d*\.\d*, '
101-
'right=\d*\.\d*',
102-
UserWarning, module='matplotlib.axes')
103-
t0 = datetime.datetime(2000, 1, 20)
104-
tf = datetime.datetime(2000, 1, 20)
105-
fig = plt.figure()
106-
ax = fig.add_subplot(1, 1, 1)
107-
ax.set_xlim((t0, tf), auto=True)
108-
ax.plot([], [])
109-
ax.xaxis.set_major_locator(mdates.DayLocator())
110-
with pytest.raises(RuntimeError):
111-
fig.savefig('junk.png')
112-
113-
11491
@image_comparison(baseline_images=['RRuleLocator_bounds'], extensions=['png'])
11592
def test_RRuleLocator():
11693
import matplotlib.testing.jpl_units as units

lib/matplotlib/ticker.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,10 @@ class Locator(TickHelper):
13961396
# kill the machine when you try and render them.
13971397
# This parameter is set to cause locators to raise an error if too
13981398
# many ticks are generated.
1399-
MAXTICKS = 1000
1399+
@property
1400+
@cbook.deprecated("2.1")
1401+
def MAXTICKS(self):
1402+
return 1000
14001403

14011404
def tick_values(self, vmin, vmax):
14021405
"""
@@ -1429,6 +1432,7 @@ def __call__(self):
14291432
# hence there is no *one* interface to call self.tick_values.
14301433
raise NotImplementedError('Derived must override')
14311434

1435+
@cbook.deprecated("2.1")
14321436
def raise_if_exceeds(self, locs):
14331437
"""raise a RuntimeError if Locator attempts to create more than
14341438
MAXTICKS locs"""
@@ -1555,7 +1559,7 @@ def tick_values(self, vmin, vmax):
15551559
ticks1 = self.locs[i::step]
15561560
if np.abs(ticks1).min() < np.abs(ticks).min():
15571561
ticks = ticks1
1558-
return self.raise_if_exceeds(ticks)
1562+
return ticks
15591563

15601564

15611565
class NullLocator(Locator):
@@ -1614,18 +1618,14 @@ def tick_values(self, vmin, vmax):
16141618
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
16151619
if vmax < vmin:
16161620
vmin, vmax = vmax, vmin
1617-
16181621
if (vmin, vmax) in self.presets:
16191622
return self.presets[(vmin, vmax)]
1620-
16211623
if self.numticks is None:
16221624
self._set_numticks()
1623-
16241625
if self.numticks == 0:
16251626
return []
16261627
ticklocs = np.linspace(vmin, vmax, self.numticks)
1627-
1628-
return self.raise_if_exceeds(ticklocs)
1628+
return ticklocs
16291629

16301630
def _set_numticks(self):
16311631
self.numticks = 11 # todo; be smart here; this is just for dev
@@ -1725,7 +1725,7 @@ def tick_values(self, vmin, vmax):
17251725
base = self._base.get_base()
17261726
n = (vmax - vmin + 0.001 * base) // base
17271727
locs = vmin - base + np.arange(n + 3) * base
1728-
return self.raise_if_exceeds(locs)
1728+
return locs
17291729

17301730
def view_limits(self, dmin, dmax):
17311731
"""
@@ -1940,7 +1940,7 @@ def tick_values(self, vmin, vmax):
19401940
locs = locs[:-1]
19411941
elif prune == 'both':
19421942
locs = locs[1:-1]
1943-
return self.raise_if_exceeds(locs)
1943+
return locs
19441944

19451945
def view_limits(self, dmin, dmax):
19461946
if self._symmetric:
@@ -2142,7 +2142,7 @@ def tick_values(self, vmin, vmax):
21422142
else:
21432143
ticklocs = b ** decades
21442144

2145-
return self.raise_if_exceeds(np.asarray(ticklocs))
2145+
return np.asarray(ticklocs)
21462146

21472147
def view_limits(self, vmin, vmax):
21482148
'Try to choose the view limits intelligently'
@@ -2323,7 +2323,7 @@ def get_log_range(lo, hi):
23232323
else:
23242324
ticklocs = decades
23252325

2326-
return self.raise_if_exceeds(np.array(ticklocs))
2326+
return np.array(ticklocs)
23272327

23282328
def view_limits(self, vmin, vmax):
23292329
'Try to choose the view limits intelligently'
@@ -2414,7 +2414,7 @@ def tick_values(self, vmin, vmax):
24142414
newticks = 1 - np.outer(np.arange(2, 10), 10**expo).ravel()
24152415
ticklocs.extend(list(newticks))
24162416

2417-
return self.raise_if_exceeds(np.array(ticklocs))
2417+
return np.array(ticklocs)
24182418

24192419
def nonsingular(self, vmin, vmax):
24202420
initial_range = (1e-7, 1 - 1e-7)
@@ -2519,7 +2519,7 @@ def __call__(self):
25192519
else:
25202520
locs = []
25212521

2522-
return self.raise_if_exceeds(np.array(locs))
2522+
return np.array(locs)
25232523

25242524
def tick_values(self, vmin, vmax):
25252525
raise NotImplementedError('Cannot get tick locations for a '
@@ -2538,7 +2538,7 @@ def __init__(self):
25382538
def __call__(self):
25392539
'Return the locations of the ticks'
25402540
self.refresh()
2541-
return self.raise_if_exceeds(self._locator())
2541+
return self._locator()
25422542

25432543
def tick_values(self, vmin, vmax):
25442544
raise NotImplementedError('Cannot get tick locations for a '

0 commit comments

Comments
 (0)