Description
Problem
As discussed in #23525, the legend treats every label as distinct and will therefore display them even when visually indistinguishable.
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 behaviorduplicate=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.