Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
anika3943 wants to merge1 commit intomatplotlib:mainfromanika3943:main

Conversation

anika3943
Copy link

Summary

This PR adds a default legend handler formatplotlib.collections.PatchCollection, enabling automatic legend support without the need for manual proxy artists.

Motivation

As discussed in issue#23998, currentlyPatchCollection 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

  • IntroducedHandlerPatchCollection (subclassingHandlerPatch) that mirrorsHandlerPolyCollection.
  • Registered the handler in_default_handler_map to enable automatic use.

Related Issues

Fixes#23998
Closes#24028

Example

frommatplotlib.patchesimportPolygonfrommatplotlib.collectionsimportPatchCollectionimportmatplotlib.pyplotaspltfig,ax=plt.subplots()p1=Polygon([[0,0], [1,1], [2,0]])p2=Polygon([[3,0], [4,1], [5,0]])coll=PatchCollection([p1,p2],label='Polygons',facecolor='cyan')ax.add_collection(coll)ax.set_xlim(0,6)ax.set_ylim(0,2)ax.legend()plt.show()

Copy link

@github-actionsgithub-actionsbot left a 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.

Copy link
Member

@rcomerrcomer left a comment
edited
Loading

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
Copy link
Member

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.

@rcomerrcomer closed thisApr 21, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@rcomerrcomerrcomer left review comments

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Labels for PatchCollection do not show
2 participants
@anika3943@rcomer

[8]ページ先頭

©2009-2025 Movatter.jp