Add HandlerPatchCollection to support legends for PatchCollection#29952
Add HandlerPatchCollection to support legends for PatchCollection#29952anika3943 wants to merge 1 commit intomatplotlib:mainfrom
Conversation
There was a problem hiding this comment.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
There was a problem hiding this comment.
Thanks @anika3943 for the potential contribution. However, the failing checks below show that your implementation is broken. Did you run the example code you posted to see if it works?
For new features, we also require several other changes in addition to the main code change. Please see the checklist here. A lot of that work is already done in #24028, and you are very welcome to re-use those changes if they seem correct.
Finally, I see you have used your main branch, which we recommend against. So, instead of continuing here, I suggest starting again with a new branch and making a new pull request when that is ready. You may find the steps set out at Start a Pull Request useful.
So I will close this one here. Note we also have the incubator gitter channel for new people to get help if you need it.
| p.set_transform(trans) | ||
| return [p] | ||
|
|
||
| from matplotlib.legend_handler import HandlerPatchCollection |
There was a problem hiding this comment.
This module is legend_handler, so you do not need to import from it.
Summary
This PR adds a default legend handler for
matplotlib.collections.PatchCollection, enabling automatic legend support without the need for manual proxy artists.Motivation
As discussed in issue #23998, currently
PatchCollectionobjects do not appear in legends because they lack a registered legend handler. This change introduces aHandlerPatchCollectionthat extracts visual properties from the first patch in the collection and uses them to generate a representative patch for the legend.Implementation
HandlerPatchCollection(subclassingHandlerPatch) that mirrorsHandlerPolyCollection._default_handler_mapto enable automatic use.Related Issues
Fixes #23998
Closes #24028
Example