Skip to content

Commit

Permalink
ENH: Add API from minor locators to opt-out of tick deconfliction
Browse files Browse the repository at this point in the history
This adds the logic to check if there is an attribute on the minor
locator to control the deconfliction.
  • Loading branch information
tacaswell committed Apr 1, 2019
1 parent 7680c19 commit 59b9308
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,9 @@ def get_minorticklocs(self):
# Remove minor ticks duplicating major ticks.
major_locs = self.major.locator()
minor_locs = self.minor.locator()
# we do check when we set the attribute that this is a Locator subclass,
# use getattr out of an over abundance of caution
remove_overlaps = getattr(self.minor.locator, 'remove_overlaps', True)
transform = self._scale.get_transform()
tr_minor_locs = transform.transform(minor_locs)
tr_major_locs = transform.transform(major_locs)
Expand All @@ -1325,7 +1328,8 @@ def get_minorticklocs(self):
tol = (hi - lo) * 1e-5
minor_locs = [
loc for loc, tr_loc in zip(minor_locs, tr_minor_locs)
if not np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any()]
if (not remove_overlaps or
not np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any())]
return minor_locs

def get_ticklocs(self, minor=False):
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,11 @@ class Locator(TickHelper):
# many ticks are generated.
MAXTICKS = 1000

# Default to requsting minor locators have overlapping ticks with the
# major locator removed. If you want to have overlapping ticks, set
# this to False on the Locator instance.
remove_overlaps = True

def tick_values(self, vmin, vmax):
"""
Return the values of the located ticks given **vmin** and **vmax**.
Expand Down

0 comments on commit 59b9308

Please sign in to comment.