Skip to content

Backport PR #13314 on branch v3.1.x (Move major/minor tick overstrike logic to Axis.) #13498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/api/next_api_changes/2018-01-30-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Minor Locator no longer try to avoid overstriking major Locators
````````````````````````````````````````````````````````````````

Previously, certain locator classes (`LogLocator`, `AutoMinorLocator`)
contained custom logic to avoid emitting tick locations that collided with
major ticks when they were used as minor locators.

This logic has now moved to the Axis class; thus, for example,
``xaxis.minor.locator()`` now includes positions that collide with
``xaxis.major.locator()``, but ``xaxis.get_minorticklocs()`` does not.
39 changes: 24 additions & 15 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,17 +1011,15 @@ def _set_artist_props(self, a):

def iter_ticks(self):
"""
Iterate through all of the major and minor ticks.
Yield ``(Tick, location, label)`` tuples for major and minor ticks.
"""
major_locs = self.major.locator()
major_ticks = self.get_major_ticks(len(major_locs))
major_locs = self.get_majorticklocs()
major_labels = self.major.formatter.format_ticks(major_locs)

minor_locs = self.minor.locator()
minor_ticks = self.get_minor_ticks(len(minor_locs))
minor_labels = self.minor.formatter.format_ticks(minor_locs)

major_ticks = self.get_major_ticks(len(major_locs))
yield from zip(major_ticks, major_locs, major_labels)
minor_locs = self.get_minorticklocs()
minor_labels = self.minor.formatter.format_ticks(minor_locs)
minor_ticks = self.get_minor_ticks(len(minor_locs))
yield from zip(minor_ticks, minor_locs, minor_labels)

def get_ticklabel_extents(self, renderer):
Expand Down Expand Up @@ -1297,18 +1295,29 @@ def get_ticklines(self, minor=False):
return self.get_majorticklines()

def get_majorticklocs(self):
"Get the major tick locations in data coordinates as a numpy array"
"""Get the array of major tick locations in data coordinates."""
return self.major.locator()

def get_minorticklocs(self):
"Get the minor tick locations in data coordinates as a numpy array"
return self.minor.locator()
"""Get the array of minor tick locations in data coordinates."""
# Remove minor ticks duplicating major ticks.
major_locs = self.major.locator()
minor_locs = self.minor.locator()
transform = self._scale.get_transform()
tr_minor_locs = transform.transform(minor_locs)
tr_major_locs = transform.transform(major_locs)
lo, hi = sorted(transform.transform(self.get_view_interval()))
# 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 np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any()]
return minor_locs

def get_ticklocs(self, minor=False):
"Get the tick locations in data coordinates as a numpy array"
if minor:
return self.minor.locator()
return self.major.locator()
"""Get the array of tick locations in data coordinates."""
return self.get_minorticklocs() if minor else self.get_majorticklocs()

def get_ticks_direction(self, minor=False):
"""
Expand Down
Binary file not shown.
Loading