Skip to content

Commit cf45de8

Browse files
authored
Merge pull request #12860 from jor-/LogLocator-subs
ENH: LogLocator: check for correct dimension of subs added
2 parents 145ade6 + 06507f2 commit cf45de8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/matplotlib/tests/test_ticker.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,3 +1260,12 @@ def test_remove_overlap(remove_overlapping_locs, expected_num):
12601260
assert len(ax.xaxis.get_minor_ticks()) == expected_num
12611261
assert len(ax.xaxis.get_minorticklabels()) == expected_num
12621262
assert len(ax.xaxis.get_minorticklines()) == expected_num*2
1263+
1264+
1265+
@pytest.mark.parametrize('sub', [
1266+
['hi', 'aardvark'],
1267+
np.zeros((2, 2))])
1268+
def test_bad_locator_subs(sub):
1269+
ll = mticker.LogLocator()
1270+
with pytest.raises(ValueError):
1271+
ll.subs(sub)

lib/matplotlib/ticker.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,16 @@ def subs(self, subs):
23822382
cbook._check_in_list(('all', 'auto'), subs=subs)
23832383
self._subs = subs
23842384
else:
2385-
self._subs = np.asarray(subs, dtype=float)
2385+
try:
2386+
self._subs = np.asarray(subs, dtype=float)
2387+
except ValueError as e:
2388+
raise ValueError("subs must be None, 'all', 'auto' or "
2389+
"a sequence of floats, not "
2390+
"{}.".format(subs)) from e
2391+
if self._subs.ndim != 1:
2392+
raise ValueError("A sequence passed to subs must be "
2393+
"1-dimensional, not "
2394+
"{}-dimensional.".format(self._subs.ndim))
23862395

23872396
def __call__(self):
23882397
'Return the locations of the ticks'

0 commit comments

Comments
 (0)