Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe55fdf

Browse files
committed
Deprecate unused canvas parameter to MultiCursor
Closes#21496.
1 parentdb83eff commitbe55fdf

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

‎galleries/examples/widgets/multicursor.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
fig,ax3=plt.subplots()
2727
ax3.plot(t,s3)
2828

29-
multi=MultiCursor(None,(ax1,ax2,ax3),color='r',lw=1)
29+
multi=MultiCursor((ax1,ax2,ax3),color='r',lw=1)
3030
plt.show()
3131

3232
# %%

‎lib/matplotlib/tests/test_widgets.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
importoperator
44
fromunittestimportmock
55

6+
importmatplotlibasmpl
67
frommatplotlib.backend_basesimportDrawEvent,KeyEvent,MouseEvent
78
importmatplotlib.colorsasmcolors
89
importmatplotlib.widgetsaswidgets
@@ -1680,15 +1681,22 @@ def test_polygon_selector_clear_method(ax):
16801681

16811682
@pytest.mark.parametrize("horizOn", [False,True])
16821683
@pytest.mark.parametrize("vertOn", [False,True])
1683-
deftest_MultiCursor(horizOn,vertOn):
1684+
@pytest.mark.parametrize("with_deprecated_canvas", [False,True])
1685+
deftest_MultiCursor(horizOn,vertOn,with_deprecated_canvas):
16841686
fig=plt.figure()
16851687
(ax1,ax3)=fig.subplots(2,sharex=True)
16861688
ax2=plt.figure().subplots()
16871689

1688-
# useblit=false to avoid having to draw the figure to cache the renderer
1689-
multi=widgets.MultiCursor(
1690-
None, (ax1,ax2),useblit=False,horizOn=horizOn,vertOn=vertOn
1691-
)
1690+
ifwith_deprecated_canvas:
1691+
withpytest.warns(mpl.MatplotlibDeprecationWarning,match=r"canvas.*deprecat"):
1692+
multi=widgets.MultiCursor(
1693+
None, (ax1,ax2),useblit=False,horizOn=horizOn,vertOn=vertOn
1694+
)
1695+
else:
1696+
# useblit=false to avoid having to draw the figure to cache the renderer
1697+
multi=widgets.MultiCursor(
1698+
(ax1,ax2),useblit=False,horizOn=horizOn,vertOn=vertOn
1699+
)
16921700

16931701
# Only two of the axes should have a line drawn on them.
16941702
assertlen(multi.vlines)==2

‎lib/matplotlib/widgets.py‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,12 +1989,19 @@ class MultiCursor(Widget):
19891989
Provide a vertical (default) and/or horizontal line cursor shared between
19901990
multiple Axes.
19911991
1992+
Call signatures::
1993+
1994+
MultiCursor(axes, *, ...)
1995+
MultiCursor(canvas, axes, *, ...) # deprecated
1996+
19921997
For the cursor to remain responsive you must keep a reference to it.
19931998
19941999
Parameters
19952000
----------
19962001
canvas : object
1997-
This parameter is entirely unused and only kept for back-compatibility.
2002+
This parameter is entirely unused.
2003+
2004+
.. deprecated:: 3.11
19982005
19992006
axes : list of `~matplotlib.axes.Axes`
20002007
The `~.axes.Axes` to attach the cursor to.
@@ -2021,11 +2028,25 @@ class MultiCursor(Widget):
20212028
See :doc:`/gallery/widgets/multicursor`.
20222029
"""
20232030

2024-
def__init__(self,canvas,axes,*,useblit=True,horizOn=False,vertOn=True,
2031+
def__init__(self,*args,useblit=True,horizOn=False,vertOn=True,
20252032
**lineprops):
2026-
# canvas is stored only to provide the deprecated .canvas attribute;
2027-
# once it goes away the unused argument won't need to be stored at all.
2028-
self._canvas=canvas
2033+
# Deprecation of canvas as the first attribute. When the deprecation exprires:
2034+
# - change the signature to __init__(self, axes, *, ...)
2035+
# - delete the "Call signatures" block in the docstring
2036+
# - delete this block
2037+
kwargs= {k:lineprops.pop(k)
2038+
forkinlist(lineprops)ifkin ("canvas","axes")}
2039+
params=_api.select_matching_signature(
2040+
[lambdaaxes:locals(),lambdacanvas,axes:locals()],*args,**kwargs)
2041+
if"canvas"inparams:
2042+
_api.warn_deprecated(
2043+
"3.11",
2044+
message="The canvas parameter in MultiCursor is unused and deprecated "
2045+
"since %(since)s. Please remove it and call MultiCursor(axes) "
2046+
"instead of MultiCursor(canvas, axes). The latter will start raising "
2047+
"an error in %(removal)s"
2048+
)
2049+
axes=params["axes"]
20292050

20302051
self.axes=axes
20312052
self.horizOn=horizOn

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp