diff --git a/lib/matplotlib/_api/__init__.py b/lib/matplotlib/_api/__init__.py index ee00665c4f1d..13319d867dc5 100644 --- a/lib/matplotlib/_api/__init__.py +++ b/lib/matplotlib/_api/__init__.py @@ -151,12 +151,10 @@ def check_shape(shape, /, **kwargs): 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( - 'MNLIJKLH', + '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) + 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 += "," diff --git a/lib/matplotlib/tests/test_api.py b/lib/matplotlib/tests/test_api.py index 34549efb0534..8b0f1e70114e 100644 --- a/lib/matplotlib/tests/test_api.py +++ b/lib/matplotlib/tests/test_api.py @@ -17,17 +17,19 @@ T = TypeVar('T') -@pytest.mark.parametrize('target,test_shape', - [((None, ), (1, 3)), - ((None, 3), (1,)), - ((None, 3), (1, 2)), - ((1, 5), (1, 9)), - ((None, 2, None), (1, 3, 1)) +@pytest.mark.parametrize('target,shape_repr,test_shape', + [((None, ), "(N,)", (1, 3)), + ((None, 3), "(N, 3)", (1,)), + ((None, 3), "(N, 3)", (1, 2)), + ((1, 5), "(1, 5)", (1, 9)), + ((None, 2, None), "(M, 2, N)", (1, 3, 1)) ]) def test_check_shape(target: tuple[int | None, ...], + shape_repr: str, test_shape: tuple[int, ...]) -> None: - error_pattern = (f"^'aardvark' must be {len(target)}D.*" + - re.escape(f'has shape {test_shape}')) + error_pattern = "^" + re.escape( + f"'aardvark' must be {len(target)}D with shape {shape_repr}, but your input " + f"has shape {test_shape}") data = np.zeros(test_shape) with pytest.raises(ValueError, match=error_pattern): _api.check_shape(target, aardvark=data)