diff --git a/ci/mypy-stubtest-allowlist.txt b/ci/mypy-stubtest-allowlist.txt index 58daf948c03b..f446fd27b87b 100644 --- a/ci/mypy-stubtest-allowlist.txt +++ b/ci/mypy-stubtest-allowlist.txt @@ -81,6 +81,8 @@ matplotlib.ticker.LogLocator.set_params matplotlib.axes._base._AxesBase.axis # Aliases (dynamically generated, not type hinted) +matplotlib.collections.Collection.get_aa +matplotlib.collections.Collection.get_antialiaseds matplotlib.collections.Collection.get_dashes matplotlib.collections.Collection.get_ec matplotlib.collections.Collection.get_edgecolors diff --git a/doc/api/next_api_changes/deprecations/26399-REC.rst b/doc/api/next_api_changes/deprecations/26399-REC.rst new file mode 100644 index 000000000000..99af88b8d9ea --- /dev/null +++ b/doc/api/next_api_changes/deprecations/26399-REC.rst @@ -0,0 +1,5 @@ +``ContourSet.antialiased`` +~~~~~~~~~~~~~~~~~~~~~~~~~~ +... is deprecated; use `~.Collection.get_antialiased` or +`~.Collection.set_antialiased` instead. Note that `~.Collection.get_antialiased` +returns an array. diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 68140194942b..25d339eaec97 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -696,6 +696,16 @@ def _bcast_lwls(linewidths, dashes): return linewidths, dashes + def get_antialiased(self): + """ + Get the antialiasing state for rendering. + + Returns + ------- + array of bools + """ + return self._antialiaseds + def set_antialiased(self, aa): """ Set the antialiasing state for rendering. diff --git a/lib/matplotlib/collections.pyi b/lib/matplotlib/collections.pyi index 25eece49d755..3a8fb38ebd6d 100644 --- a/lib/matplotlib/collections.pyi +++ b/lib/matplotlib/collections.pyi @@ -8,7 +8,7 @@ from .ticker import Locator, Formatter from .tri import Triangulation import numpy as np -from numpy.typing import ArrayLike +from numpy.typing import ArrayLike, NDArray from collections.abc import Callable, Iterable, Sequence from typing import Literal from .typing import ColorType, LineStyleType, CapStyleType, JoinStyleType @@ -55,6 +55,7 @@ class Collection(artist.Artist, cm.ScalarMappable): def set_joinstyle(self, js: JoinStyleType) -> None: ... def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ... def set_antialiased(self, aa: bool | Sequence[bool]) -> None: ... + def get_antialiased(self) -> NDArray[np.bool_]: ... def set_color(self, c: ColorType | Sequence[ColorType]) -> None: ... def set_facecolor(self, c: ColorType | Sequence[ColorType]) -> None: ... def get_facecolor(self) -> ColorType | Sequence[ColorType]: ... diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index ec9ec0a0f498..79f66b896131 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -943,6 +943,16 @@ def __init__(self, ax, *args, alpha = property(lambda self: self.get_alpha()) linestyles = property(lambda self: self._orig_linestyles) + @_api.deprecated("3.8", alternative="set_antialiased or get_antialiased", + addendum="Note that get_antialiased returns an array.") + @property + def antialiased(self): + return all(self.get_antialiased()) + + @antialiased.setter + def antialiased(self, aa): + self.set_antialiased(aa) + @_api.deprecated("3.8") @property def collections(self): diff --git a/lib/matplotlib/contour.pyi b/lib/matplotlib/contour.pyi index c7179637a1e1..4a1e1e1d9d2e 100644 --- a/lib/matplotlib/contour.pyi +++ b/lib/matplotlib/contour.pyi @@ -94,7 +94,6 @@ class ContourSet(ContourLabeler, Collection): extent: tuple[float, float, float, float] | None colors: ColorType | Sequence[ColorType] extend: Literal["neither", "both", "min", "max"] - antialiased: bool | None nchunk: int locator: Locator | None logscale: bool @@ -113,6 +112,10 @@ class ContourSet(ContourLabeler, Collection): @property def alpha(self) -> float | None: ... @property + def antialiased(self) -> bool: ... + @antialiased.setter + def antialiased(self, aa: bool | Sequence[bool]) -> None: ... + @property def collections(self) -> list[PathCollection]: ... @property def linestyles(self) -> ( diff --git a/lib/matplotlib/tests/test_contour.py b/lib/matplotlib/tests/test_contour.py index 006c3e81b013..20d1f7c2ad96 100644 --- a/lib/matplotlib/tests/test_contour.py +++ b/lib/matplotlib/tests/test_contour.py @@ -831,3 +831,9 @@ def test_deprecated_apis(): assert_array_equal(cs.tcolors, [c.get_edgecolor() for c in colls]) with pytest.warns(mpl.MatplotlibDeprecationWarning, match="tlinewidths"): assert cs.tlinewidths == [c.get_linewidth() for c in colls] + with pytest.warns(mpl.MatplotlibDeprecationWarning, match="antialiased"): + assert cs.antialiased + with pytest.warns(mpl.MatplotlibDeprecationWarning, match="antialiased"): + cs.antialiased = False + with pytest.warns(mpl.MatplotlibDeprecationWarning, match="antialiased"): + assert not cs.antialiased
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: