Skip to content

Commit 650323a

Browse files
committed
In SecondaryAxis.set_functions, reuse _set_scale's parent scale caching.
_set_scale checks whether the parent scale changed before modifying the secondary scale. set_functions should do the same. See added test for previously failing case.
1 parent b53418e commit 650323a

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

lib/matplotlib/axes/_secondary_axes.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,7 @@ def set_functions(self, functions):
215215
216216
If a transform is supplied, then the transform must have an
217217
inverse.
218-
219218
"""
220-
221-
if self._orientation == 'x':
222-
set_scale = self.set_xscale
223-
parent_scale = self._parent.get_xscale()
224-
else:
225-
set_scale = self.set_yscale
226-
parent_scale = self._parent.get_yscale()
227-
# we need to use a modified scale so the scale can receive the
228-
# transform. Only types supported are linear and log10 for now.
229-
# Probably possible to add other transforms as a todo...
230-
if parent_scale == 'log':
231-
defscale = 'functionlog'
232-
else:
233-
defscale = 'function'
234-
235219
if (isinstance(functions, tuple) and len(functions) == 2 and
236220
callable(functions[0]) and callable(functions[1])):
237221
# make an arbitrary convert from a two-tuple of functions
@@ -244,7 +228,7 @@ def set_functions(self, functions):
244228
'must be a two-tuple of callable functions '
245229
'with the first function being the transform '
246230
'and the second being the inverse')
247-
set_scale(defscale, functions=self._functions)
231+
self._set_scale()
248232

249233
def draw(self, renderer=None, inframe=False):
250234
"""

lib/matplotlib/tests/test_axes.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6135,6 +6135,16 @@ def invert(x):
61356135
mticker.NullLocator)
61366136

61376137

6138+
def test_secondary_formatter():
6139+
fig, ax = plt.subplots()
6140+
ax.set_xscale("log")
6141+
secax = ax.secondary_xaxis("top")
6142+
secax.xaxis.set_major_formatter(mticker.ScalarFormatter())
6143+
fig.canvas.draw()
6144+
assert isinstance(
6145+
secax.xaxis.get_major_formatter(), mticker.ScalarFormatter)
6146+
6147+
61386148
def color_boxes(fig, axs):
61396149
"""
61406150
Helper for the tests below that test the extents of various axes elements

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy