From 7680c1999f25588c33092a77a21f360d78442d58 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 31 Mar 2019 23:09:38 -0400 Subject: [PATCH 1/3] FIX: restore de-confliction logic for minor ticks In #13363 when `iter_ticks` was deprecated the in-lined logic did not account for the updates from #13314. --- lib/matplotlib/axis.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 1a903733de86..5e9391f21271 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1064,19 +1064,18 @@ def _update_ticks(self): Update ticks (position and labels) using the current data interval of the axes. Return the list of ticks that will be drawn. """ - - major_locs = self.major.locator() + major_locs = self.get_majorticklocs() + major_labels = self.major.formatter.format_ticks(major_locs) major_ticks = self.get_major_ticks(len(major_locs)) self.major.formatter.set_locs(major_locs) - major_labels = self.major.formatter.format_ticks(major_locs) for tick, loc, label in zip(major_ticks, major_locs, major_labels): tick.update_position(loc) tick.set_label1(label) tick.set_label2(label) - minor_locs = self.minor.locator() + minor_locs = self.get_minorticklocs() + minor_labels = self.minor.formatter.format_ticks(minor_locs) minor_ticks = self.get_minor_ticks(len(minor_locs)) self.minor.formatter.set_locs(minor_locs) - minor_labels = self.minor.formatter.format_ticks(minor_locs) for tick, loc, label in zip(minor_ticks, minor_locs, minor_labels): tick.update_position(loc) tick.set_label1(label) From 66429905816a617ea825ca1f5526bc8e9202d8a6 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 31 Mar 2019 14:33:22 -0400 Subject: [PATCH 2/3] 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. --- lib/matplotlib/axis.py | 6 +++++- lib/matplotlib/ticker.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 5e9391f21271..28820cc8bae1 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -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) @@ -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): diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index b29ddba2e0b6..b12363daed95 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -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**. From 62838ad1550018fa733f57366c244d15fccd8914 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 2 Apr 2019 11:58:27 -0400 Subject: [PATCH 3/3] MNT: only do filtering if we need to --- lib/matplotlib/axis.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 28820cc8bae1..1670514d8c59 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -1326,10 +1326,11 @@ def get_minorticklocs(self): # Use the transformed view limits as scale. 1e-5 is the default rtol # for np.isclose. tol = (hi - lo) * 1e-5 - minor_locs = [ - loc for loc, tr_loc in zip(minor_locs, tr_minor_locs) - if (not remove_overlaps or - not np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any())] + if remove_overlaps: + minor_locs = [ + loc for loc, tr_loc in zip(minor_locs, tr_minor_locs) + if ~(np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any()) + ] return minor_locs def get_ticklocs(self, minor=False):