Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #24965 on branch v3.7.x (Remove additional deprecations from 3.5) #24966

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
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
11 changes: 11 additions & 0 deletions doc/api/next_api_changes/removals/24948-ES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ information; modification of the following sublists is no longer supported:
To remove an Artist, use its `.Artist.remove` method. To add an Artist, use the
corresponding ``Axes.add_*`` method.

Passing incorrect types to ``Axes.add_*`` methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following ``Axes.add_*`` methods will now raise if passed an unexpected
type. See their documentation for the types they expect.

- `.Axes.add_collection`
- `.Axes.add_image`
- `.Axes.add_line`
- `.Axes.add_patch`
- `.Axes.add_table`


``ConversionInterface.convert`` no longer accepts unitless values
Expand Down
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/removals/24965-ES.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
``Colorbar`` tick update parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The *update_ticks* parameter of `.Colorbar.set_ticks` and
`.Colorbar.set_ticklabels` was ignored since 3.5 and has been removed.
27 changes: 6 additions & 21 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2203,20 +2203,6 @@ def has_data(self):
mlines.Line2D, mpatches.Patch))
for a in self._children)

def _deprecate_noninstance(self, _name, _types, **kwargs):
"""
For each *key, value* pair in *kwargs*, check that *value* is an
instance of one of *_types*; if not, raise an appropriate deprecation.
"""
for key, value in kwargs.items():
if not isinstance(value, _types):
_api.warn_deprecated(
'3.5', name=_name,
message=f'Passing argument *{key}* of unexpected type '
f'{type(value).__qualname__} to %(name)s which only '
f'accepts {_types} is deprecated since %(since)s and will '
'become an error %(removal)s.')

def add_artist(self, a):
"""
Add an `.Artist` to the Axes; return the artist.
Expand Down Expand Up @@ -2260,8 +2246,7 @@ def add_collection(self, collection, autolim=True):
"""
Add a `.Collection` to the Axes; return the collection.
"""
self._deprecate_noninstance('add_collection', mcoll.Collection,
collection=collection)
_api.check_isinstance(mcoll.Collection, collection=collection)
label = collection.get_label()
if not label:
collection.set_label(f'_child{len(self._children)}')
Expand Down Expand Up @@ -2294,7 +2279,7 @@ def add_image(self, image):
"""
Add an `.AxesImage` to the Axes; return the image.
"""
self._deprecate_noninstance('add_image', mimage.AxesImage, image=image)
_api.check_isinstance(mimage.AxesImage, image=image)
self._set_artist_props(image)
if not image.get_label():
image.set_label(f'_child{len(self._children)}')
Expand All @@ -2311,7 +2296,7 @@ def add_line(self, line):
"""
Add a `.Line2D` to the Axes; return the line.
"""
self._deprecate_noninstance('add_line', mlines.Line2D, line=line)
_api.check_isinstance(mlines.Line2D, line=line)
self._set_artist_props(line)
if line.get_clip_path() is None:
line.set_clip_path(self.patch)
Expand All @@ -2328,7 +2313,7 @@ def _add_text(self, txt):
"""
Add a `.Text` to the Axes; return the text.
"""
self._deprecate_noninstance('_add_text', mtext.Text, txt=txt)
_api.check_isinstance(mtext.Text, txt=txt)
self._set_artist_props(txt)
self._children.append(txt)
txt._remove_method = self._children.remove
Expand Down Expand Up @@ -2387,7 +2372,7 @@ def add_patch(self, p):
"""
Add a `.Patch` to the Axes; return the patch.
"""
self._deprecate_noninstance('add_patch', mpatches.Patch, p=p)
_api.check_isinstance(mpatches.Patch, p=p)
self._set_artist_props(p)
if p.get_clip_path() is None:
p.set_clip_path(self.patch)
Expand Down Expand Up @@ -2440,7 +2425,7 @@ def add_table(self, tab):
"""
Add a `.Table` to the Axes; return the table.
"""
self._deprecate_noninstance('add_table', mtable.Table, tab=tab)
_api.check_isinstance(mtable.Table, tab=tab)
self._set_artist_props(tab)
self._children.append(tab)
tab.set_clip_path(self.patch)
Expand Down
3 changes: 0 additions & 3 deletions lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,8 @@ class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
if name_of_method in _ALLOWED_TOOL_ITEMS
]

cursor = _api.deprecate_privatize_attribute("3.5")

def __init__(self, canvas):
self.message = ''
self._cursor = None # Remove with deprecation.
super().__init__(canvas)

def set_message(self, message):
Expand Down
8 changes: 2 additions & 6 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,7 @@ def _get_ticker_locator_formatter(self):
self._minorlocator = minorlocator
_log.debug('locator: %r', locator)

@_api.delete_parameter("3.5", "update_ticks")
def set_ticks(self, ticks, update_ticks=True, labels=None, *,
minor=False, **kwargs):
def set_ticks(self, ticks, *, labels=None, minor=False, **kwargs):
"""
Set tick locations.

Expand Down Expand Up @@ -916,9 +914,7 @@ def get_ticks(self, minor=False):
else:
return self._long_axis().get_majorticklocs()

@_api.delete_parameter("3.5", "update_ticks")
def set_ticklabels(self, ticklabels, update_ticks=True, *, minor=False,
**kwargs):
def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
"""
[*Discouraged*] Set tick labels.

Expand Down
12 changes: 8 additions & 4 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,11 +999,13 @@ def test_check_radio_buttons_image():
rax1 = plt.axes([0.05, 0.7, 0.15, 0.15])
rax2 = plt.axes([0.05, 0.2, 0.15, 0.15])
rb = widgets.RadioButtons(rax1, ('Radio 1', 'Radio 2', 'Radio 3'))
with pytest.warns(DeprecationWarning):
with pytest.warns(DeprecationWarning,
match='The circles attribute was deprecated'):
rb.circles # Trigger the old-style elliptic radiobuttons.
cb = widgets.CheckButtons(rax2, ('Check 1', 'Check 2', 'Check 3'),
(False, True, True))
with pytest.warns(DeprecationWarning):
with pytest.warns(DeprecationWarning,
match='The rectangles attribute was deprecated'):
cb.rectangles # Trigger old-style Rectangle check boxes


Expand Down Expand Up @@ -1034,7 +1036,8 @@ def test_check_buttons_rectangles(fig_test, fig_ref):
# Test should be removed once .rectangles is removed
cb = widgets.CheckButtons(fig_test.subplots(), ["", ""],
[False, False])
with pytest.warns(DeprecationWarning):
with pytest.warns(DeprecationWarning,
match='The rectangles attribute was deprecated'):
cb.rectangles
ax = fig_ref.add_subplot(xticks=[], yticks=[])
ys = [2/3, 1/3]
Expand All @@ -1056,7 +1059,8 @@ def test_check_buttons_rectangles(fig_test, fig_ref):
def test_check_buttons_lines(fig_test, fig_ref):
# Test should be removed once .lines is removed
cb = widgets.CheckButtons(fig_test.subplots(), ["", ""], [True, True])
with pytest.warns(DeprecationWarning):
with pytest.warns(DeprecationWarning,
match='The lines attribute was deprecated'):
cb.lines
for rectangle in cb._rectangles:
rectangle.set_visible(False)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,8 @@ def lines(self):
l1.set_visible(current_status[i])
l2.set_visible(current_status[i])
self._lines.append((l1, l2))
self.ax.add_patch(l1)
self.ax.add_patch(l2)
self.ax.add_line(l1)
self.ax.add_line(l2)
if not hasattr(self, "_rectangles"):
with _api.suppress_matplotlib_deprecation_warning():
_ = self.rectangles
Expand Down