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

Skip to content

Commit 373b965

Browse files
committed
Deprecate MAXTICKS, Locator.raise_if_exceeds.
1 parent 0084e4a commit 373b965

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

lib/matplotlib/dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def tick_values(self, vmin, vmax):
901901
dates = self.rule.between(vmin, vmax, True)
902902
if len(dates) == 0:
903903
return date2num([vmin, vmax])
904-
return self.raise_if_exceeds(date2num(dates))
904+
return date2num(dates)
905905

906906
def _get_unit(self):
907907
"""

lib/matplotlib/tests/test_dates.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,6 @@ def test_date_axvline():
8686
fig.autofmt_xdate()
8787

8888

89-
def test_too_many_date_ticks():
90-
# Attempt to test SF 2715172, see
91-
# https://sourceforge.net/tracker/?func=detail&aid=2715172&group_id=80706&atid=560720
92-
# setting equal datetimes triggers and expander call in
93-
# transforms.nonsingular which results in too many ticks in the
94-
# DayLocator. This should trigger a Locator.MAXTICKS RuntimeError
95-
t0 = datetime.datetime(2000, 1, 20)
96-
tf = datetime.datetime(2000, 1, 20)
97-
fig = plt.figure()
98-
ax = fig.add_subplot(1, 1, 1)
99-
with pytest.warns(UserWarning) as rec:
100-
ax.set_xlim((t0, tf), auto=True)
101-
assert len(rec) == 1
102-
assert 'Attempting to set identical left==right' in str(rec[0].message)
103-
ax.plot([], [])
104-
ax.xaxis.set_major_locator(mdates.DayLocator())
105-
with pytest.raises(RuntimeError):
106-
fig.savefig('junk.png')
107-
108-
10989
@image_comparison(baseline_images=['RRuleLocator_bounds'], extensions=['png'])
11090
def test_RRuleLocator():
11191
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
@@ -1422,7 +1422,10 @@ class Locator(TickHelper):
14221422
# kill the machine when you try and render them.
14231423
# This parameter is set to cause locators to raise an error if too
14241424
# many ticks are generated.
1425-
MAXTICKS = 1000
1425+
@property
1426+
@cbook.deprecated("2.1")
1427+
def MAXTICKS(self):
1428+
return 1000
14261429

14271430
def tick_values(self, vmin, vmax):
14281431
"""
@@ -1455,6 +1458,7 @@ def __call__(self):
14551458
# hence there is no *one* interface to call self.tick_values.
14561459
raise NotImplementedError('Derived must override')
14571460

1461+
@cbook.deprecated("2.1")
14581462
def raise_if_exceeds(self, locs):
14591463
"""raise a RuntimeError if Locator attempts to create more than
14601464
MAXTICKS locs"""
@@ -1581,7 +1585,7 @@ def tick_values(self, vmin, vmax):
15811585
ticks1 = self.locs[i::step]
15821586
if np.abs(ticks1).min() < np.abs(ticks).min():
15831587
ticks = ticks1
1584-
return self.raise_if_exceeds(ticks)
1588+
return ticks
15851589

15861590

15871591
class NullLocator(Locator):
@@ -1640,18 +1644,14 @@ def tick_values(self, vmin, vmax):
16401644
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
16411645
if vmax < vmin:
16421646
vmin, vmax = vmax, vmin
1643-
16441647
if (vmin, vmax) in self.presets:
16451648
return self.presets[(vmin, vmax)]
1646-
16471649
if self.numticks is None:
16481650
self._set_numticks()
1649-
16501651
if self.numticks == 0:
16511652
return []
16521653
ticklocs = np.linspace(vmin, vmax, self.numticks)
1653-
1654-
return self.raise_if_exceeds(ticklocs)
1654+
return ticklocs
16551655

16561656
def _set_numticks(self):
16571657
self.numticks = 11 # todo; be smart here; this is just for dev
@@ -1751,7 +1751,7 @@ def tick_values(self, vmin, vmax):
17511751
base = self._base.get_base()
17521752
n = (vmax - vmin + 0.001 * base) // base
17531753
locs = vmin - base + np.arange(n + 3) * base
1754-
return self.raise_if_exceeds(locs)
1754+
return locs
17551755

17561756
def view_limits(self, dmin, dmax):
17571757
"""
@@ -1966,7 +1966,7 @@ def tick_values(self, vmin, vmax):
19661966
locs = locs[:-1]
19671967
elif prune == 'both':
19681968
locs = locs[1:-1]
1969-
return self.raise_if_exceeds(locs)
1969+
return locs
19701970

19711971
def view_limits(self, dmin, dmax):
19721972
if self._symmetric:
@@ -2174,7 +2174,7 @@ def tick_values(self, vmin, vmax):
21742174
else:
21752175
ticklocs = b ** decades
21762176

2177-
return self.raise_if_exceeds(np.asarray(ticklocs))
2177+
return np.asarray(ticklocs)
21782178

21792179
def view_limits(self, vmin, vmax):
21802180
'Try to choose the view limits intelligently'
@@ -2355,7 +2355,7 @@ def get_log_range(lo, hi):
23552355
else:
23562356
ticklocs = decades
23572357

2358-
return self.raise_if_exceeds(np.array(ticklocs))
2358+
return np.array(ticklocs)
23592359

23602360
def view_limits(self, vmin, vmax):
23612361
'Try to choose the view limits intelligently'
@@ -2446,7 +2446,7 @@ def tick_values(self, vmin, vmax):
24462446
newticks = 1 - np.outer(np.arange(2, 10), 10**expo).ravel()
24472447
ticklocs.extend(list(newticks))
24482448

2449-
return self.raise_if_exceeds(np.array(ticklocs))
2449+
return np.array(ticklocs)
24502450

24512451
def nonsingular(self, vmin, vmax):
24522452
initial_range = (1e-7, 1 - 1e-7)
@@ -2553,7 +2553,7 @@ def __call__(self):
25532553
cond = np.abs((locs - t0) % majorstep) > minorstep / 10.0
25542554
locs = locs.compress(cond)
25552555

2556-
return self.raise_if_exceeds(np.array(locs))
2556+
return np.array(locs)
25572557

25582558
def tick_values(self, vmin, vmax):
25592559
raise NotImplementedError('Cannot get tick locations for a '
@@ -2572,7 +2572,7 @@ def __init__(self):
25722572
def __call__(self):
25732573
'Return the locations of the ticks'
25742574
self.refresh()
2575-
return self.raise_if_exceeds(self._locator())
2575+
return self._locator()
25762576

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

0 commit comments

Comments
 (0)