From 2642831068b99b2266cc0c0da829e5880de41591 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Sat, 22 Sep 2018 10:39:56 +0200 Subject: [PATCH] Axes.tick_params() argument checking --- doc/api/next_api_changes/2018-09-22-TH.rst | 5 +++++ lib/matplotlib/axes/_base.py | 2 ++ lib/mpl_toolkits/mplot3d/axes3d.py | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 doc/api/next_api_changes/2018-09-22-TH.rst diff --git a/doc/api/next_api_changes/2018-09-22-TH.rst b/doc/api/next_api_changes/2018-09-22-TH.rst new file mode 100644 index 000000000000..c299f77fb1fb --- /dev/null +++ b/doc/api/next_api_changes/2018-09-22-TH.rst @@ -0,0 +1,5 @@ +Axes.tick_params argument checking +`````````````````````````````````` + +`Axes.tick_params` silently did nothing when an invalid *axis* parameter was +supplied. This behavior is changed to raise a ValueError instead. diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index b732c6e5779d..ef2b8966bb51 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2949,6 +2949,8 @@ def tick_params(self, axis='both', **kwargs): also be red. Gridlines will be red and translucent. """ + if axis not in ['x', 'y', 'both']: + raise ValueError("axis must be one of 'x', 'y' or 'both'") if axis in ['x', 'both']: xkw = dict(kwargs) xkw.pop('left', None) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index d26fed20ebc4..c7b06df58545 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1412,7 +1412,10 @@ def tick_params(self, axis='both', **kwargs): .. versionadded :: 1.1.0 This function was added, but not tested. Please report any bugs. """ - super().tick_params(axis, **kwargs) + if axis not in ['x', 'y', 'z', 'both']: + raise ValueError("axis must be one of 'x', 'y', 'z' or 'both'") + if axis in ['x', 'y', 'both']: + super().tick_params(axis, **kwargs) if axis in ['z', 'both']: zkw = dict(kwargs) zkw.pop('top', None)