Deprecate mixing positional and keyword args for legend(handles, labels) by anntzer · Pull Request #27175 · matplotlib/matplotlib · GitHub
Skip to content
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/deprecations/27175-AL.rst
8 changes: 5 additions & 3 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff 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 Down Expand 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 deletions lib/matplotlib/tests/test_legend.py