Skip to content

Commit 5f0b714

Browse files
Add input check to secondary axes
1 parent 64c7765 commit 5f0b714

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,17 @@ def invert(x):
582582
secax.set_xlabel('Period [s]')
583583
plt.show()
584584
"""
585-
if location in ['top', 'bottom'] or isinstance(location, Real):
586-
secondary_ax = SecondaryAxis(self, 'x', location, functions,
587-
transform, **kwargs)
588-
self.add_child_axes(secondary_ax)
589-
return secondary_ax
590-
else:
585+
if not (location in ['top', 'bottom'] or isinstance(location, Real)):
591586
raise ValueError('secondary_xaxis location must be either '
592587
'a float or "top"/"bottom"')
588+
if not (isinstance(transform, mtransforms.Transform) or transform is None):
589+
raise ValueError('transform must be either an mtransforms.Transform '
590+
'or None')
591+
592+
secondary_ax = SecondaryAxis(self, 'x', location, functions,
593+
transform, **kwargs)
594+
self.add_child_axes(secondary_ax)
595+
return secondary_ax
593596

594597
@_docstring.dedent_interpd
595598
def secondary_yaxis(self, location, *, functions=None, transform=None, **kwargs):
@@ -614,14 +617,16 @@ def secondary_yaxis(self, location, *, functions=None, transform=None, **kwargs)
614617
np.rad2deg))
615618
secax.set_ylabel('radians')
616619
"""
617-
if location in ['left', 'right'] or isinstance(location, Real):
618-
secondary_ax = SecondaryAxis(self, 'y', location, functions,
619-
transform, **kwargs)
620-
self.add_child_axes(secondary_ax)
621-
return secondary_ax
622-
else:
623-
raise ValueError('secondary_yaxis location must be either '
620+
if not (location in ['left', 'right'] or isinstance(location, Real)):
621+
raise ValueError('secondary_xaxis location must be either '
624622
'a float or "left"/"right"')
623+
if not (isinstance(transform, mtransforms.Transform) or transform is None):
624+
raise ValueError('transform must be either an mtransforms.Transform '
625+
'or None')
626+
secondary_ax = SecondaryAxis(self, 'y', location, functions,
627+
transform, **kwargs)
628+
self.add_child_axes(secondary_ax)
629+
return secondary_ax
625630

626631
@_docstring.dedent_interpd
627632
def text(self, x, y, s, fontdict=None, **kwargs):

0 commit comments

Comments
 (0)