Skip to content

Commit c51aa67

Browse files
committed
Return minorticks as array, not as list.
The return type changed accidentally when remove_overlapping_locs was introduced (except for NullLocator, which always returned a plain list). Make the API consistent with majorticks, which are (mostly) always returned as an array. Modifying the test in test_colorbar is so-so, but that's the only place, AFAICT, that currently tests anything with get_ticklocs(minor=True), so...
1 parent f96eb63 commit c51aa67

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

lib/matplotlib/axis.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,19 +1269,19 @@ def get_majorticklocs(self):
12691269
def get_minorticklocs(self):
12701270
"""Return this Axis' minor tick locations in data coordinates."""
12711271
# Remove minor ticks duplicating major ticks.
1272-
major_locs = self.major.locator()
1273-
minor_locs = self.minor.locator()
1274-
transform = self._scale.get_transform()
1275-
tr_minor_locs = transform.transform(minor_locs)
1276-
tr_major_locs = transform.transform(major_locs)
1277-
lo, hi = sorted(transform.transform(self.get_view_interval()))
1278-
# Use the transformed view limits as scale. 1e-5 is the default rtol
1279-
# for np.isclose.
1280-
tol = (hi - lo) * 1e-5
1272+
minor_locs = np.asarray(self.minor.locator())
12811273
if self.remove_overlapping_locs:
1282-
minor_locs = [
1283-
loc for loc, tr_loc in zip(minor_locs, tr_minor_locs)
1284-
if ~np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any()]
1274+
major_locs = self.major.locator()
1275+
transform = self._scale.get_transform()
1276+
tr_minor_locs = transform.transform(minor_locs)
1277+
tr_major_locs = transform.transform(major_locs)
1278+
lo, hi = sorted(transform.transform(self.get_view_interval()))
1279+
# Use the transformed view limits as scale. 1e-5 is the default
1280+
# rtol for np.isclose.
1281+
tol = (hi - lo) * 1e-5
1282+
mask = np.isclose(tr_minor_locs[:, None], tr_major_locs[None, :],
1283+
atol=tol, rtol=0).any(axis=1)
1284+
minor_locs = minor_locs[~mask]
12851285
return minor_locs
12861286

12871287
def get_ticklocs(self, *, minor=False):

lib/matplotlib/tests/test_colorbar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ def test_colorbar_inverted_ticks():
608608
cbar.minorticks_on()
609609
ticks = cbar.get_ticks()
610610
minorticks = cbar.get_ticks(minor=True)
611+
assert isinstance(minorticks, np.ndarray)
611612
cbar.ax.invert_yaxis()
612613
np.testing.assert_allclose(ticks, cbar.get_ticks())
613614
np.testing.assert_allclose(minorticks, cbar.get_ticks(minor=True))

0 commit comments

Comments
 (0)