diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index 0e8c0f50e150..22048b408e6e 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -1014,6 +1014,7 @@ def mkdirs(newdir, mode=0o777): if exception.errno != errno.EEXIST: raise + class GetRealpathAndStat(object): def __init__(self): self._cache = {} @@ -1734,7 +1735,7 @@ def recursive_remove(path): os.removedirs(fname) else: os.remove(fname) - #os.removedirs(path) + # os.removedirs(path) else: os.remove(path) @@ -2701,3 +2702,19 @@ def __exit__(self, exc_type, exc_value, traceback): os.rmdir(path) except OSError: pass + + +def _check_array(obj): + """ + Helper function to check whether the input is an array or + can be casted to an array type object. + + If it is not an array or cannot be casted to an array + type obejct, it will raise an error to notify users that + they should use array. Otherwise, it will return the casted + array type object. + """ + cast_obj = np.asanyarray(obj) + if isinstance(cast_obj, np.matrix): + raise ValueError("The input cannot be matrix") + return cast_obj diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 594ca8744ef2..0f0472ae7923 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -372,12 +372,13 @@ def _parse_args(*args): X, Y, U, V, C = [None] * 5 args = list(args) - # The use of atleast_1d allows for handling scalar arguments while also - # keeping masked arrays - if len(args) == 3 or len(args) == 5: + if len(args) == 2 or len(args) == 4: + V = np.atleast_1d(args.pop(-1)) + U = np.atleast_1d(args.pop(-1)) + elif len(args) == 3 or len(args) == 5: C = np.atleast_1d(args.pop(-1)) - V = np.atleast_1d(args.pop(-1)) - U = np.atleast_1d(args.pop(-1)) + V = np.atleast_1d(args.pop(-1)) + U = np.atleast_1d(args.pop(-1)) if U.ndim == 1: nr, nc = 1, U.shape[0] else: @@ -389,6 +390,9 @@ def _parse_args(*args): else: indexgrid = np.meshgrid(np.arange(nc), np.arange(nr)) X, Y = [np.ravel(a) for a in indexgrid] + cbook._check_array(U) + cbook._check_array(V) + cbook._check_array(C) return X, Y, U, V, C