From 863ad9d3954bd742c005434285e4c32fa07e932e Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 31 Jan 2017 10:31:24 -0800 Subject: [PATCH] More cbook deprecations. `is_scalar_or_string` was not used anymore, `is_scalar` was only used in one place (in mplot3d) and I rewrote that snippet into something more robust. --- lib/matplotlib/cbook/__init__.py | 2 ++ lib/mpl_toolkits/mplot3d/axes3d.py | 38 ++++++++++-------------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 48fd0bd93eb2..21bb742149e1 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -543,6 +543,7 @@ def file_requires_unicode(x): return False +@deprecated('2.1') def is_scalar(obj): """return true if *obj* is not string like and is not iterable""" return not is_string_like(obj) and not iterable(obj) @@ -582,6 +583,7 @@ def to_filehandle(fname, flag='rU', return_opened=False): return fh +@deprecated('2.1') def is_scalar_or_string(val): """Return whether the given object is a scalar or string like.""" return is_string_like(val) or not iterable(val) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index ad29a21d1643..f630315037a4 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -1503,39 +1503,25 @@ def plot(self, xs, ys, *args, **kwargs): Other arguments are passed on to :func:`~matplotlib.axes.Axes.plot` ''' - # FIXME: This argument parsing might be better handled - # when we set later versions of python for - # minimum requirements. Currently at 2.4. - # Note that some of the reason for the current difficulty - # is caused by the fact that we want to insert a new - # (semi-optional) positional argument 'Z' right before - # many other traditional positional arguments occur - # such as the color, linestyle and/or marker. had_data = self.has_data() - zs = kwargs.pop('zs', 0) - zdir = kwargs.pop('zdir', 'z') - argsi = 0 - # First argument is array of zs - if args and cbook.iterable(args[0]) and len(xs) == len(args[0]): - # So, we know that it is an array with - # first dimension the same as xs. - # Next, check to see if the data contained - # therein (if any) is scalar (and not another array). - if len(args[0]) == 0 or cbook.is_scalar(args[0][0]): - zs = args[argsi] - argsi += 1 - - # First argument is z value - elif args and cbook.is_scalar(args[0]): - zs = args[argsi] - argsi += 1 + # `zs` can be passed positionally or as keyword; checking with + # `_is_string_like` matches the behavior of 2D `plot` (via + # `_process_plot_var_args`). + if args and not cbook.is_string_like(args[0]): + zs = args[0] + args = args[1:] + if 'zs' in kwargs: + raise TypeError("plot() for multiple values for argument 'z'") + else: + zs = kwargs.pop('zs', 0) + zdir = kwargs.pop('zdir', 'z') # Match length if not cbook.iterable(zs): zs = np.ones(len(xs)) * zs - lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs) + lines = Axes.plot(self, xs, ys, *args, **kwargs) for line in lines: art3d.line_2d_to_3d(line, zs=zs, zdir=zdir)