Skip to content

Commit a3011df

Browse files
authored
Merge pull request matplotlib#24965 from QuLogic/more-deprecations
Remove additional deprecations from 3.5
2 parents 018c5ef + c1a8406 commit a3011df

File tree

7 files changed

+34
-36
lines changed

7 files changed

+34
-36
lines changed

doc/api/next_api_changes/removals/24948-ES.rst

+11
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ information; modification of the following sublists is no longer supported:
4444
To remove an Artist, use its `.Artist.remove` method. To add an Artist, use the
4545
corresponding ``Axes.add_*`` method.
4646

47+
Passing incorrect types to ``Axes.add_*`` methods
48+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49+
50+
The following ``Axes.add_*`` methods will now raise if passed an unexpected
51+
type. See their documentation for the types they expect.
52+
53+
- `.Axes.add_collection`
54+
- `.Axes.add_image`
55+
- `.Axes.add_line`
56+
- `.Axes.add_patch`
57+
- `.Axes.add_table`
4758

4859

4960
``ConversionInterface.convert`` no longer accepts unitless values
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``Colorbar`` tick update parameters
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The *update_ticks* parameter of `.Colorbar.set_ticks` and
5+
`.Colorbar.set_ticklabels` was ignored since 3.5 and has been removed.

lib/matplotlib/axes/_base.py

+6-21
Original file line numberDiff line numberDiff line change
@@ -2203,20 +2203,6 @@ def has_data(self):
22032203
mlines.Line2D, mpatches.Patch))
22042204
for a in self._children)
22052205

2206-
def _deprecate_noninstance(self, _name, _types, **kwargs):
2207-
"""
2208-
For each *key, value* pair in *kwargs*, check that *value* is an
2209-
instance of one of *_types*; if not, raise an appropriate deprecation.
2210-
"""
2211-
for key, value in kwargs.items():
2212-
if not isinstance(value, _types):
2213-
_api.warn_deprecated(
2214-
'3.5', name=_name,
2215-
message=f'Passing argument *{key}* of unexpected type '
2216-
f'{type(value).__qualname__} to %(name)s which only '
2217-
f'accepts {_types} is deprecated since %(since)s and will '
2218-
'become an error %(removal)s.')
2219-
22202206
def add_artist(self, a):
22212207
"""
22222208
Add an `.Artist` to the Axes; return the artist.
@@ -2260,8 +2246,7 @@ def add_collection(self, collection, autolim=True):
22602246
"""
22612247
Add a `.Collection` to the Axes; return the collection.
22622248
"""
2263-
self._deprecate_noninstance('add_collection', mcoll.Collection,
2264-
collection=collection)
2249+
_api.check_isinstance(mcoll.Collection, collection=collection)
22652250
label = collection.get_label()
22662251
if not label:
22672252
collection.set_label(f'_child{len(self._children)}')
@@ -2294,7 +2279,7 @@ def add_image(self, image):
22942279
"""
22952280
Add an `.AxesImage` to the Axes; return the image.
22962281
"""
2297-
self._deprecate_noninstance('add_image', mimage.AxesImage, image=image)
2282+
_api.check_isinstance(mimage.AxesImage, image=image)
22982283
self._set_artist_props(image)
22992284
if not image.get_label():
23002285
image.set_label(f'_child{len(self._children)}')
@@ -2311,7 +2296,7 @@ def add_line(self, line):
23112296
"""
23122297
Add a `.Line2D` to the Axes; return the line.
23132298
"""
2314-
self._deprecate_noninstance('add_line', mlines.Line2D, line=line)
2299+
_api.check_isinstance(mlines.Line2D, line=line)
23152300
self._set_artist_props(line)
23162301
if line.get_clip_path() is None:
23172302
line.set_clip_path(self.patch)
@@ -2328,7 +2313,7 @@ def _add_text(self, txt):
23282313
"""
23292314
Add a `.Text` to the Axes; return the text.
23302315
"""
2331-
self._deprecate_noninstance('_add_text', mtext.Text, txt=txt)
2316+
_api.check_isinstance(mtext.Text, txt=txt)
23322317
self._set_artist_props(txt)
23332318
self._children.append(txt)
23342319
txt._remove_method = self._children.remove
@@ -2387,7 +2372,7 @@ def add_patch(self, p):
23872372
"""
23882373
Add a `.Patch` to the Axes; return the patch.
23892374
"""
2390-
self._deprecate_noninstance('add_patch', mpatches.Patch, p=p)
2375+
_api.check_isinstance(mpatches.Patch, p=p)
23912376
self._set_artist_props(p)
23922377
if p.get_clip_path() is None:
23932378
p.set_clip_path(self.patch)
@@ -2440,7 +2425,7 @@ def add_table(self, tab):
24402425
"""
24412426
Add a `.Table` to the Axes; return the table.
24422427
"""
2443-
self._deprecate_noninstance('add_table', mtable.Table, tab=tab)
2428+
_api.check_isinstance(mtable.Table, tab=tab)
24442429
self._set_artist_props(tab)
24452430
self._children.append(tab)
24462431
tab.set_clip_path(self.patch)

lib/matplotlib/backends/backend_webagg_core.py

-3
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,8 @@ class NavigationToolbar2WebAgg(backend_bases.NavigationToolbar2):
390390
if name_of_method in _ALLOWED_TOOL_ITEMS
391391
]
392392

393-
cursor = _api.deprecate_privatize_attribute("3.5")
394-
395393
def __init__(self, canvas):
396394
self.message = ''
397-
self._cursor = None # Remove with deprecation.
398395
super().__init__(canvas)
399396

400397
def set_message(self, message):

lib/matplotlib/colorbar.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,7 @@ def _get_ticker_locator_formatter(self):
875875
self._minorlocator = minorlocator
876876
_log.debug('locator: %r', locator)
877877

878-
@_api.delete_parameter("3.5", "update_ticks")
879-
def set_ticks(self, ticks, update_ticks=True, labels=None, *,
880-
minor=False, **kwargs):
878+
def set_ticks(self, ticks, *, labels=None, minor=False, **kwargs):
881879
"""
882880
Set tick locations.
883881
@@ -916,9 +914,7 @@ def get_ticks(self, minor=False):
916914
else:
917915
return self._long_axis().get_majorticklocs()
918916

919-
@_api.delete_parameter("3.5", "update_ticks")
920-
def set_ticklabels(self, ticklabels, update_ticks=True, *, minor=False,
921-
**kwargs):
917+
def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
922918
"""
923919
[*Discouraged*] Set tick labels.
924920

lib/matplotlib/tests/test_widgets.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -999,11 +999,13 @@ def test_check_radio_buttons_image():
999999
rax1 = plt.axes([0.05, 0.7, 0.15, 0.15])
10001000
rax2 = plt.axes([0.05, 0.2, 0.15, 0.15])
10011001
rb = widgets.RadioButtons(rax1, ('Radio 1', 'Radio 2', 'Radio 3'))
1002-
with pytest.warns(DeprecationWarning):
1002+
with pytest.warns(DeprecationWarning,
1003+
match='The circles attribute was deprecated'):
10031004
rb.circles # Trigger the old-style elliptic radiobuttons.
10041005
cb = widgets.CheckButtons(rax2, ('Check 1', 'Check 2', 'Check 3'),
10051006
(False, True, True))
1006-
with pytest.warns(DeprecationWarning):
1007+
with pytest.warns(DeprecationWarning,
1008+
match='The rectangles attribute was deprecated'):
10071009
cb.rectangles # Trigger old-style Rectangle check boxes
10081010

10091011

@@ -1034,7 +1036,8 @@ def test_check_buttons_rectangles(fig_test, fig_ref):
10341036
# Test should be removed once .rectangles is removed
10351037
cb = widgets.CheckButtons(fig_test.subplots(), ["", ""],
10361038
[False, False])
1037-
with pytest.warns(DeprecationWarning):
1039+
with pytest.warns(DeprecationWarning,
1040+
match='The rectangles attribute was deprecated'):
10381041
cb.rectangles
10391042
ax = fig_ref.add_subplot(xticks=[], yticks=[])
10401043
ys = [2/3, 1/3]
@@ -1056,7 +1059,8 @@ def test_check_buttons_rectangles(fig_test, fig_ref):
10561059
def test_check_buttons_lines(fig_test, fig_ref):
10571060
# Test should be removed once .lines is removed
10581061
cb = widgets.CheckButtons(fig_test.subplots(), ["", ""], [True, True])
1059-
with pytest.warns(DeprecationWarning):
1062+
with pytest.warns(DeprecationWarning,
1063+
match='The lines attribute was deprecated'):
10601064
cb.lines
10611065
for rectangle in cb._rectangles:
10621066
rectangle.set_visible(False)

lib/matplotlib/widgets.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,8 @@ def lines(self):
11921192
l1.set_visible(current_status[i])
11931193
l2.set_visible(current_status[i])
11941194
self._lines.append((l1, l2))
1195-
self.ax.add_patch(l1)
1196-
self.ax.add_patch(l2)
1195+
self.ax.add_line(l1)
1196+
self.ax.add_line(l2)
11971197
if not hasattr(self, "_rectangles"):
11981198
with _api.suppress_matplotlib_deprecation_warning():
11991199
_ = self.rectangles

0 commit comments

Comments
 (0)