Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Add HandlerPatchCollection to support legends for PatchCollection#29952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 uson gitter for real-time discussion.
For details on testing, writing docs, and our review process, please seethe developer guide
We strive to be a welcoming and open project. Please follow ourCode of Conduct.
rcomer left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 thechecklist 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 yourmain
branch, which werecommend 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 atStart a Pull Request useful.
So I will close this one here. Note we also have theincubator gitter channel for new people to get help if you need it.
@@ -810,3 +810,42 @@ def create_artists(self, legend, orig_handle, | |||
self.update_prop(p, orig_handle, legend) | |||
p.set_transform(trans) | |||
return [p] | |||
from matplotlib.legend_handler import HandlerPatchCollection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This moduleislegend_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
PatchCollection
objects do not appear in legends because they lack a registered legend handler. This change introduces aHandlerPatchCollection
that 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_map
to enable automatic use.Related Issues
Fixes#23998
Closes#24028
Example