matplotlib/matplotlib · error · ValueError

{k!r} must be {len(shape)}D with shape ({text_shape}), but y

Error message

{k!r} must be {len(shape)}D with shape ({text_shape}), but your input has shape {v.shape}

What it means

Error "{k!r} must be {len(shape)}D with shape ({text_shape}), but your input has shape {v.shape}" thrown in matplotlib/matplotlib.

Source

Thrown at lib/matplotlib/_api/__init__.py:258

    --------
    To check for (N, 2) shaped arrays

    >>> _api.check_shape((None, 2), arg=arg, other_arg=other_arg)
    """
    for k, v in kwargs.items():
        data_shape = v.shape

        if (len(data_shape) != len(shape)
                or any(s != t and t is not None for s, t in zip(data_shape, shape))):
            dim_labels = iter(itertools.chain(
                'NMLKJIH',
                (f"D{i}" for i in itertools.count())))
            text_shape = ", ".join([str(n) if n is not None else next(dim_labels)
                                    for n in shape[::-1]][::-1])
            if len(shape) == 1:
                text_shape += ","

            raise ValueError(
                f"{k!r} must be {len(shape)}D with shape ({text_shape}), "
                f"but your input has shape {v.shape}"
            )


def getitem_checked(mapping, /, _error_cls=ValueError, **kwargs):
    """
    *kwargs* must consist of a single *key, value* pair.  If *key* is in
    *mapping*, return ``mapping[value]``; else, raise an appropriate
    ValueError.

    Parameters
    ----------
    _error_cls :
        Class of error to raise.

    Examples
    --------

View on GitHub (pinned to b379c1b69e)

When it happens

Trigger: Thrown at lib/matplotlib/_api/__init__.py:258 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of matplotlib/matplotlib@b379c1b69e (2026-08-21). Data as JSON: /api/errors/0b12717370480d97. Report an issue: GitHub.