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

Deprecate mixing positional and keyword args for legend(handles, labels)#27175

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dstansby merged 1 commit intomatplotlib:mainfromanntzer:lpk
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes fromall 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
5 changes: 5 additions & 0 deletionsdoc/api/next_api_changes/deprecations/27175-AL.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
Mixing positional and keyword arguments for ``legend`` handles and labels
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This previously only raised a warning, but is now formally deprecated. If
passing *handles* and *labels*, they must be passed either both positionally or
both as keyword.
8 changes: 5 additions & 3 deletionslib/matplotlib/legend.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1301,7 +1301,7 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs):
legend(handles=handles, labels=labels)

The behavior for a mixture of positional and keyword handles and labels
is undefined and issues a warning.
is undefined and issues a warning; it will be an error in the future.

Parameters
----------
Expand DownExpand Up@@ -1334,8 +1334,10 @@ def _parse_legend_args(axs, *args, handles=None, labels=None, **kwargs):
handlers = kwargs.get('handler_map')

if (handles is not None or labels is not None) and args:
_api.warn_external("You have mixed positional and keyword arguments, "
"some input may be discarded.")
_api.warn_deprecated("3.9", message=(
"You have mixed positional and keyword arguments, some input may "
"be discarded. This is deprecated since %(since)s and will "
"become an error %(removal)s."))

if (hasattr(handles, "__len__") and
hasattr(labels, "__len__") and
Expand Down
8 changes: 4 additions & 4 deletionslib/matplotlib/tests/test_legend.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -405,10 +405,10 @@ def test_warn_mixed_args_and_kwargs(self):
th = np.linspace(0, 2*np.pi, 1024)
lns, = ax.plot(th, np.sin(th), label='sin')
lnc, = ax.plot(th, np.cos(th), label='cos')
with pytest.warns(UserWarning) as record:
with pytest.warns(DeprecationWarning) as record:
ax.legend((lnc, lns), labels=('a', 'b'))
assert len(record) == 1
assert str(record[0].message) ==(
assert str(record[0].message).startswith(
"You have mixed positional and keyword arguments, some input may "
"be discarded.")

Expand DownExpand Up@@ -474,10 +474,10 @@ def test_warn_args_kwargs(self):
fig, axs = plt.subplots(1, 2)
lines = axs[0].plot(range(10))
lines2 = axs[1].plot(np.arange(10) * 2.)
with pytest.warns(UserWarning) as record:
with pytest.warns(DeprecationWarning) as record:
fig.legend((lines, lines2), labels=('a', 'b'))
assert len(record) == 1
assert str(record[0].message) ==(
assert str(record[0].message).startswith(
"You have mixed positional and keyword arguments, some input may "
"be discarded.")

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp