8000 ENH: Add API from minor locators to opt-out of tick deconfliction · matplotlib/matplotlib@6642990 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6642990

Browse files
committed
ENH: Add API from minor locators to opt-out of tick deconfliction
This adds the logic to check if there is an attribute on the minor locator to control the deconfliction.
1 parent 7680c19 commit 6642990

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/matplotlib/axis.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,9 @@ def get_minorticklocs(self):
13161316
# Remove minor ticks duplicating major ticks.
13171317
major_locs = self.major.locator()
13181318
minor_locs = self.minor.locator()
1319+
# we do check when we set the attribute that this is a Locator
1320+
# subclass, use getattr out of an over abundance of caution
1321+
remove_overlaps = getattr(self.minor.locator, 'remove_overlaps', True)
13191322
transform = self._scale.get_transform()
13201323
tr_minor_locs = transform.transform(minor_locs)
13211324
tr_major_locs = transform.transform(major_locs)
@@ -1325,7 +1328,8 @@ def get_minorticklocs(self):
13251328
tol = (hi - lo) * 1e-5
13261329
minor_locs = [
13271330
loc for loc, tr_loc in zip(minor_locs, tr_minor_locs)
1328-
if not np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any()]
1331+
if (not remove_overlaps or
1332+
not np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any())]
13291333
return minor_locs
13301334

13311335
def get_ticklocs(self, minor=False):

lib/matplotlib/ticker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,11 @@ class Locator(TickHelper):
14691469
# many ticks are generated.
14701470
MAXTICKS = 1000
14711471

1472+
# Default to requsting minor locators have overlapping ticks with the
1473+
# major locator removed. If you want to have overlapping ticks, set
1474+
# this to False on the Locator instance.
1475+
remove_overlaps = True
1476+
14721477
def tick_values(self, vmin, vmax):
14731478
"""
14741479
Return the values of the located ticks given **vmin** and **vmax**.

0 commit comments

Comments
 (0)
0