8000 FIX: allow secondary axes minor locators to be set by jklymak · Pull Request #14447 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: allow secondary axes minor locators to be set #14447

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
merged 2 commits into from
Jun 20, 2019
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
6 changes: 6 additions & 0 deletions lib/matplotlib/axes/_secondary_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self, parent, orientation,
self._axis = self.yaxis
self._locstrings = ['right', 'left']
self._otherstrings = ['top', 'bottom']
self._parentscale = self._axis.get_scale()
# this gets positioned w/o constrained_layout so exclude:
self._layoutbox = None
self._poslayoutbox = None
Expand Down Expand Up @@ -272,6 +273,11 @@ def _set_scale(self):
if self._orientation == 'y':
pscale = self._parent.yaxis.get_scale()
set_scale = self.set_yscale
if pscale == self._parentscale:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want == or is here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ==, get_scale returns a string. Well really we should retrieve the scale object rather than a scale string, but that's a separate issue...

return
else:
self._parentscale = pscale

if pscale == 'log':
defscale = 'functionlog'
else:
Expand Down
24 changes: 24 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import matplotlib.markers as mmarkers
import matplotlib.patches as mpatches
import matplotlib.colors as mcolors
import matplotlib.ticker as mticker
import matplotlib.transforms as mtransforms
from numpy.testing import (
assert_allclose, assert_array_equal, assert_array_almost_equal)
Expand Down Expand Up @@ -6079,6 +6080,29 @@ def invert(x):
assert_allclose(ax.get_position().extents, [0.125, 0.1, 0.9, 0.9])


def test_secondary_minorloc():
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot(np.arange(2, 11), np.arange(2, 11))
def invert(x):
with np.errstate(divide='ignore'):
return 1 / x

secax = ax.secondary_xaxis('top', functions=(invert, invert))
assert isinstance(secax._axis.get_minor_locator(),
mticker.NullLocator)
secax.minorticks_on()
assert isinstance(secax._axis.get_minor_locator(),
mticker.AutoMinorLocator)
ax.set_xscale('log')
plt.draw()
assert isinstance(secax._axis.get_minor_locator(),
mticker.LogLocator)
ax.set_xscale('linear')
plt.draw()
assert isinstance(secax._axis.get_minor_locator(),
mticker.NullLocator)


def color_boxes(fig, axs):
"""
Helper for the tests below that test the extents of various axes elements
Expand Down
0