Skip to content

Reinstate & deprecate ContourSet.antialiased #26399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/mypy-stubtest-allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/deprecations/26399-REC.rst
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 10 additions & 0 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/collections.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]: ...
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecation needs to be added to the getter and setter individually (otherwise users who use only the setter will not be warned)

Copy link
Member Author

@rcomer rcomer Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for both - I've updated the test to show that. I also tried adding the deprecation to both but with different warning messages: this gave me both messages whether I was setting or getting.

In [3]: cs.antialiased = False
<ipython-input-3-e2ba4606272c>:1: MatplotlibDeprecationWarning: The antialiased attribute was deprecated in Matplotlib 3.8 and will be removed two minor releases later. Use set_antialiased instead.
  cs.antialiased = False
<ipython-input-3-e2ba4606272c>:1: MatplotlibDeprecationWarning: The antialiased attribute was deprecated in Matplotlib 3.8 and will be removed two minor releases later. Use get_antialiased instead. Note that get_antialiased returns an array.
  cs.antialiased = False

def antialiased(self, aa):
self.set_antialiased(aa)

@_api.deprecated("3.8")
@property
def collections(self):
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/contour.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -113,6 +112,10 @@ class ContourSet(ContourLabeler, Collection):
@property
def alpha(self) -> float | None: ...
@property
def antialiased(self) -> bool: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setter should be added to the pyi as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@antialiased.setter
def antialiased(self, aa: bool | Sequence[bool]) -> None: ...
@property
def collections(self) -> list[PathCollection]: ...
@property
def linestyles(self) -> (
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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