10000 More strict handling of legend(labels) · Issue #18107 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
More strict handling of legend(labels) #18107
Open
@timhoffm

Description

@timhoffm

We already discourage legend(labels) in the docs:

Note: This way of using is discouraged, because the relation between plot elements and labels is only implicit by their order and can easily be mixed up.

Additionally, this API is very permissive:

  • If there are less labels than artists, only the first len(labels) artists are labelled.
  • If there are more labels than artists, additional labels are silently ignored.

IMHO this length adaption is very prone to hiding errors.

Possible options if the number of labels does not match the number of available handles:

  1. Emit a warning.
  2. Deprecate the length adaption and error out in the future.
  3. Deprecate the whole legend(labels) API, because it's prone to misuse anyway. (This would us also enable in the long run to migrate to an explicit legend(handles=None, labels=None, **kwargs) signature instead of legend(*args, **kwargs).)

I tend to go with option 2. Comments are welcome.

Inspired by #18096.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0