With a single transform (class or object), or a tuple of transform objects, it fails in the setter:
Traceback (most recent call last):
File "galleries/examples/subplots_axes_and_figures/secondary_axis.py", line 40, in <module>
secax = ax.secondary_xaxis('top', functions=IdentityTransform)
File "lib/matplotlib/axes/_axes.py", line 586, in secondary_xaxis
secondary_ax = SecondaryAxis(self, 'x', location, functions,
File "lib/matplotlib/axes/_secondary_axes.py", line 42, in __init__self.set_functions(functions)
File "lib/matplotlib/axes/_secondary_axes.py", line 155, in set_functionsraiseValueError('functions argument of secondary axes 'ValueError: functions argument of secondary axes must be a two-tuple of callable functions with the first function being the transform and the second being the inverse
With a tuple of transform classes, the setter allows it, but it fails when drawing:
Traceback (most recent call last):
File "lib/matplotlib/backends/backend_qt.py", line 461, in _draw_idle
self.draw()
File "lib/matplotlib/backends/backend_agg.py", line 401, in draw
self.figure.draw(self.renderer)
File "lib/matplotlib/artist.py", line 95, in draw_wrapper
result = draw(artist, renderer, *args, **kwargs)
File "lib/matplotlib/artist.py", line 72, in draw_wrapper
return draw(artist, renderer)
File "lib/matplotlib/figure.py", line 3115, in draw
artists = self._get_draw_artists(renderer)
File "lib/matplotlib/figure.py", line 225, in _get_draw_artists
child.apply_aspect(
File "lib/matplotlib/axes/_secondary_axes.py", line 120, in apply_aspect
self._set_lims()
File "lib/matplotlib/axes/_secondary_axes.py", line 216, in _set_lims
lims = self._functions[0](np.array(lims))
File "lib/matplotlib/transforms.py", line 1759, in __init__
super().__init__(*args, **kwargs)
File "lib/matplotlib/transforms.py", line 125, in __init__
self._shorthand_name = shorthand_name or ''
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Expected outcome
At least one of the options works, or it should not be documented as accepted.
Additional information
I noticed this oddity in the types while reviewing #25224, but not sure what we intend here.
Activity
jklymak commented on Apr 15, 2023
That seems like an oversight, or something that got lost in the shuffle of adding a forward and inverse.
I don't think we should allow a tuple of transforms - one of the advantages of using a transform is that it has an inverse?
QuLogic commented on May 5, 2023
I don't think it's necessary; it's just something I tried to get past the checks and see if the internals were fine with it.