8000 [ENH]: Suppress duplicate labels in legend · Issue #23664 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[ENH]: Suppress duplicate labels in legend #23664
Closed as not planned
Closed as not planned
@story645

Description

@story645

Problem

As discussed in #23525, the legend treats every label as distinct and will therefore display them even when visually indistinguishable.
image

Proposed solution

@timhoffm raised the good point that we don't want to break the artist-(label, handle) link in case the artist gets updated, so I think an alternative solution is maybe to have this logic in the legend. Something like a duplicate keyword argument to legend:

  • duplicate=True, default, current behavior
  • duplicate=False - triggers a check of legend objects. If multiple legend handles have the same properties (class, color/edgecolor, hatch, size/width/edgewidth, etc) and the same label, then a new handle with those properties linked to all the artists is shown in place of the original handles.

I'm not sure if this is even doable in the current architecture, but if possible this would be designed so that updates to properties that update handles/legends propagate back to create new entries on the legend as needed. The advantage of this approach is that it would facilitate explicitly linking legend labels & handles to multiple artists.

I think currently duplicates are eliminated manually either by omitting the labels on some artists or creating a custom legend handle. Neither approach preserves a link between a legend entry and all the artists it is intended to describe.

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