Skip to content

Commit c12be12

Browse files
authored
Merge pull request #26399 from rcomer/contourset-antialias
Reinstate & deprecate ContourSet.antialiased
2 parents 00afcc0 + 035d3e3 commit c12be12

File tree

7 files changed

+39
-2
lines changed

7 files changed

+39
-2
lines changed

ci/mypy-stubtest-allowlist.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ matplotlib.ticker.LogLocator.set_params
8181
matplotlib.axes._base._AxesBase.axis
8282

8383
# Aliases (dynamically generated, not type hinted)
84+
matplotlib.collections.Collection.get_aa
85+
matplotlib.collections.Collection.get_antialiaseds
8486
matplotlib.collections.Collection.get_dashes
8587
matplotlib.collections.Collection.get_ec
8688
matplotlib.collections.Collection.get_edgecolors
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``ContourSet.antialiased``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated; use `~.Collection.get_antialiased` or
4+
`~.Collection.set_antialiased` instead. Note that `~.Collection.get_antialiased`
5+
returns an array.

lib/matplotlib/collections.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,16 @@ def _bcast_lwls(linewidths, dashes):
696696

697697
return linewidths, dashes
698698

699+
def get_antialiased(self):
700+
"""
701+
Get the antialiasing state for rendering.
702+
703+
Returns
704+
-------
705+
array of bools
706+
"""
707+
return self._antialiaseds
708+
699709
def set_antialiased(self, aa):
700710
"""
701711
Set the antialiasing state for rendering.

lib/matplotlib/collections.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ from .ticker import Locator, Formatter
88
from .tri import Triangulation
99

1010
import numpy as np
11-
from numpy.typing import ArrayLike
11+
from numpy.typing import ArrayLike, NDArray
1212
from collections.abc import Callable, Iterable, Sequence
1313
from typing import Literal
1414
from .typing import ColorType, LineStyleType, CapStyleType, JoinStyleType
@@ -55,6 +55,7 @@ class Collection(artist.Artist, cm.ScalarMappable):
5555
def set_joinstyle(self, js: JoinStyleType) -> None: ...
5656
def get_joinstyle(self) -> Literal["miter", "round", "bevel"]: ...
5757
def set_antialiased(self, aa: bool | Sequence[bool]) -> None: ...
58+
def get_antialiased(self) -> NDArray[np.bool_]: ...
5859
def set_color(self, c: ColorType | Sequence[ColorType]) -> None: ...
5960
def set_facecolor(self, c: ColorType | Sequence[ColorType]) -> None: ...
6061
def get_facecolor(self) -> ColorType | Sequence[ColorType]: ...

lib/matplotlib/contour.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,16 @@ def __init__(self, ax, *args,
943943
alpha = property(lambda self: self.get_alpha())
944944
linestyles = property(lambda self: self._orig_linestyles)
945945

946+
@_api.deprecated("3.8", alternative="set_antialiased or get_antialiased",
947+
addendum="Note that get_antialiased returns an array.")
948+
@property
949+
def antialiased(self):
950+
return all(self.get_antialiased())
951+
952+
@antialiased.setter
953+
def antialiased(self, aa):
954+
self.set_antialiased(aa)
955+
946956
@_api.deprecated("3.8")
947957
@property
948958
def collections(self):

lib/matplotlib/contour.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class ContourSet(ContourLabeler, Collection):
9494
extent: tuple[float, float, float, float] | None
9595
colors: ColorType | Sequence[ColorType]
9696
extend: Literal["neither", "both", "min", "max"]
97-
antialiased: bool | None
9897
nchunk: int
9998
locator: Locator | None
10099
logscale: bool
@@ -113,6 +112,10 @@ class ContourSet(ContourLabeler, Collection):
113112
@property
114113
def alpha(self) -> float | None: ...
115114
@property
115+
def antialiased(self) -> bool: ...
116+
@antialiased.setter
117+
def antialiased(self, aa: bool | Sequence[bool]) -> None: ...
118+
@property
116119
def collections(self) -> list[PathCollection]: ...
117120
@property
118121
def linestyles(self) -> (

lib/matplotlib/tests/test_contour.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,3 +831,9 @@ def test_deprecated_apis():
831831
assert_array_equal(cs.tcolors, [c.get_edgecolor() for c in colls])
832832
with pytest.warns(mpl.MatplotlibDeprecationWarning, match="tlinewidths"):
833833
assert cs.tlinewidths == [c.get_linewidth() for c in colls]
834+
with pytest.warns(mpl.MatplotlibDeprecationWarning, match="antialiased"):
835+
assert cs.antialiased
836+
with pytest.warns(mpl.MatplotlibDeprecationWarning, match="antialiased"):
837+
cs.antialiased = False
838+
with pytest.warns(mpl.MatplotlibDeprecationWarning, match="antialiased"):
839+
assert not cs.antialiased

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy