diff --git a/doc/api/next_api_changes/deprecations/22883-AL.rst b/doc/api/next_api_changes/deprecations/22883-AL.rst new file mode 100644 index 000000000000..916658e6f1e2 --- /dev/null +++ b/doc/api/next_api_changes/deprecations/22883-AL.rst @@ -0,0 +1,3 @@ +Passing too many positional arguments to ``tripcolor`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +... is now deprecated (extra arguments were previously silently ignored). diff --git a/lib/matplotlib/tests/test_triangulation.py b/lib/matplotlib/tests/test_triangulation.py index ee2b28c47473..8435d87dca86 100644 --- a/lib/matplotlib/tests/test_triangulation.py +++ b/lib/matplotlib/tests/test_triangulation.py @@ -242,7 +242,7 @@ def test_tripcolor_color(): x = [-1, 0, 1, 0] y = [0, -1, 0, 1] fig, ax = plt.subplots() - with pytest.raises(ValueError, match="Missing color parameter"): + with pytest.raises(TypeError, match=r"tripcolor\(\) missing 1 required "): ax.tripcolor(x, y) with pytest.raises(ValueError, match="The length of C must match either"): ax.tripcolor(x, y, [1, 2, 3]) @@ -255,8 +255,8 @@ def test_tripcolor_color(): with pytest.raises(ValueError, match="'gouraud' .* at the points.* not at the faces"): ax.tripcolor(x, y, [1, 2], shading='gouraud') # faces - with pytest.raises(ValueError, - match=r"pass C positionally or facecolors via keyword"): + with pytest.raises(TypeError, + match="positional.*'C'.*keyword-only.*'facecolors'"): ax.tripcolor(x, y, C=[1, 2, 3, 4]) # smoke test for valid color specifications (via C or facecolors) @@ -282,7 +282,7 @@ def test_tripcolor_warnings(): C = [0.4, 0.5] fig, ax = plt.subplots() # additional parameters - with pytest.warns(UserWarning, match="Additional positional parameters"): + with pytest.warns(DeprecationWarning, match="Additional positional param"): ax.tripcolor(x, y, C, 'unused_positional') # facecolors takes precednced over C with pytest.warns(UserWarning, match="Positional parameter C .*no effect"): diff --git a/lib/matplotlib/tri/tripcolor.py b/lib/matplotlib/tri/tripcolor.py index 6c3edc77600a..3dfec365a2a2 100644 --- a/lib/matplotlib/tri/tripcolor.py +++ b/lib/matplotlib/tri/tripcolor.py @@ -79,12 +79,14 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None, else: # Color from positional parameter C if not args: - raise ValueError( - "Missing color parameter. Please pass C positionally or " - "facecolors via keyword") + raise TypeError( + "tripcolor() missing 1 required positional argument: 'C'; or " + "1 required keyword-only argument: 'facecolors'") elif len(args) > 1: - _api.warn_external( - "Additional positional parameters {args[1:]!r} are ignored") + _api.warn_deprecated( + "3.6", message=f"Additional positional parameters " + f"{args[1:]!r} are ignored; support for them is deprecated " + f"since %(since)s and will be removed %(removal)s") C = np.asarray(args[0]) if len(C) == len(tri.x): # having this before the len(tri.triangles) comparison gives