diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index b5f66bc33224..640a3fac48c8 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -504,9 +504,7 @@ def _create_lookup_table(N, data, gamma=1.0): adata = np.array(data) except Exception as err: raise TypeError("data must be convertible to an array") from err - shape = adata.shape - if len(shape) != 2 or shape[1] != 3: - raise ValueError("data must be nx3 format") + _api.check_shape((None, 3), data=adata) x = adata[:, 0] y0 = adata[:, 1] diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index d7ac521242a5..c3d1b7929128 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -1656,11 +1656,10 @@ def transform_angles(self, angles, pts, radians=False, pushoff=1e-5): raise NotImplementedError('Only defined in 2D') angles = np.asarray(angles) pts = np.asarray(pts) - if angles.ndim != 1 or angles.shape[0] != pts.shape[0]: - raise ValueError("'angles' must be a column vector and have same " - "number of rows as 'pts'") - if pts.shape[1] != 2: - raise ValueError("'pts' must be array with 2 columns for x, y") + _api.check_shape((None, 2), pts=pts) + _api.check_shape((None,), angles=angles) + if len(angles) != len(pts): + raise ValueError("There must be as many 'angles' as 'pts'") # Convert to radians if desired if not radians: angles = np.deg2rad(angles) diff --git a/lib/matplotlib/tri/triinterpolate.py b/lib/matplotlib/tri/triinterpolate.py index 581477619fc1..f6c439d29015 100644 --- a/lib/matplotlib/tri/triinterpolate.py +++ b/lib/matplotlib/tri/triinterpolate.py @@ -1406,8 +1406,7 @@ def _safe_inv22_vectorized(M): *M* : array of (2, 2) matrices to inverse, shape (n, 2, 2) """ - assert M.ndim == 3 - assert M.shape[-2:] == (2, 2) + _api.check_shape((None, 2, 2), M=M) M_inv = np.empty_like(M) prod1 = M[:, 0, 0]*M[:, 1, 1] delta = prod1 - M[:, 0, 1]*M[:, 1, 0] @@ -1441,8 +1440,7 @@ def _pseudo_inv22sym_vectorized(M): *M* : array of (2, 2) matrices to inverse, shape (n, 2, 2) """ - assert M.ndim == 3 - assert M.shape[-2:] == (2, 2) + _api.check_shape((None, 2, 2), M=M) M_inv = np.empty_like(M) prod1 = M[:, 0, 0]*M[:, 1, 1] delta = prod1 - M[:, 0, 1]*M[:, 1, 0] diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 34e6d9a4a948..d94bf6443f5d 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -893,11 +893,8 @@ def set_val(self, val): ---------- val : tuple or array-like of float """ - val = np.sort(np.asanyarray(val)) - if val.shape != (2,): - raise ValueError( - f"val must have shape (2,) but has shape {val.shape}" - ) + val = np.sort(val) + _api.check_shape((2,), val=val) val[0] = self._min_in_bounds(val[0]) val[1] = self._max_in_bounds(val[1]) xy = self.poly.xy diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 605e0d8e8211..3aaf31610d29 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -343,13 +343,8 @@ def set_box_aspect(self, aspect, *, zoom=1): if aspect is None: aspect = np.asarray((4, 4, 3), dtype=float) else: - orig_aspect = aspect aspect = np.asarray(aspect, dtype=float) - if aspect.shape != (3,): - raise ValueError( - "You must pass a 3-tuple that can be cast to floats. " - f"You passed {orig_aspect!r}" - ) + _api.check_shape((3,), aspect=aspect) # default scale tuned to match the mpl32 appearance. aspect *= 1.8294640721620434 * zoom / np.linalg.norm(aspect)