8000 In SecondaryAxis.set_functions, reuse _set_scale's parent scale caching. by anntzer · Pull Request #14592 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

In SecondaryAxis.set_functions, reuse _set_scale's parent scale caching. #14592

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 1 commit into from
Feb 25, 2020
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
25 changes: 5 additions & 20 deletions lib/matplotlib/axes/_secondary_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, parent, orientation,
self._axis = self.yaxis
self._locstrings = ['right', 'left']
self._otherstrings = ['top', 'bottom']
self._parentscale = self._axis.get_scale()
self._parentscale = None
# this gets positioned w/o constrained_layout so exclude:
self._layoutbox = None
self._poslayoutbox = None
Expand Down Expand Up @@ -195,21 +195,6 @@ def set_functions(self, functions):
If a transform is supplied, then the transform must have an
inverse.
"""

if self._orientation == 'x':
set_scale = self.set_xscale
parent_scale = self._parent.get_xscale()
else:
set_scale = self.set_yscale
parent_scale = self._parent.get_yscale()
# we need to use a modified scale so the scale can receive the
# transform. Only types supported are linear and log10 for now.
# Probably possible to add other transforms as a todo...
if parent_scale == 'log':
defscale = 'functionlog'
else:
defscale = 'function'

if (isinstance(functions, tuple) and len(functions) == 2 and
callable(functions[0]) and callable(functions[1])):
# make an arbitrary convert from a two-tuple of functions
Expand All @@ -222,8 +207,7 @@ def set_functions(self, functions):
'must be a two-tuple of callable functions '
'with the first function being the transform '
'and the second being the inverse')
# need to invert the roles here for the ticks to line up.
set_scale(defscale, functions=self._functions[::-1])
self._set_scale()

def draw(self, renderer=None, inframe=False):
"""
Expand Down Expand Up @@ -252,8 +236,6 @@ def _set_scale(self):
set_scale = self.set_yscale
if pscale == self._parentscale:
return
else:
self._parentscale = pscale

if pscale == 'log':
defscale = 'functionlog'
Expand All @@ -271,6 +253,9 @@ def _set_scale(self):
if self._ticks_set:
self._axis.set_major_locator(mticker.FixedLocator(ticks))

# If the parent scale doesn't change, we can skip this next time.
self._parentscale = pscale

def _set_lims(self):
"""
Set the limits based on parent limits and the convert method
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6544,6 +6544,16 @@ def invert(x):
mticker.NullLocator)


def test_secondary_formatter():
fig, ax = plt.subplots()
ax.set_xscale("log")
secax = ax.secondary_xaxis("top")
secax.xaxis.set_major_formatter(mticker.ScalarFormatter())
fig.canvas.draw()
assert isinstance(
secax.xaxis.get_major_formatter(), mticker.ScalarFormatter)


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