Title: Add HandlerPatchCollection to support legends for PatchCollection by anika3943 · Pull Request #29952 · matplotlib/matplotlib · GitHub
Open Graph Title: Add HandlerPatchCollection to support legends for PatchCollection by anika3943 · Pull Request #29952 · matplotlib/matplotlib
X Title: Add HandlerPatchCollection to support legends for PatchCollection by anika3943 · Pull Request #29952 · matplotlib/matplotlib
Description: 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 a HandlerPatchCollection that extracts visual properties from the first patch in the collection and uses them to generate a representative patch for the legend. Implementation Introduced HandlerPatchCollection (subclassing HandlerPatch) that mirrors HandlerPolyCollection. Registered the handler in _default_handler_map to enable automatic use. Related Issues Fixes #23998 Closes #24028 Example from matplotlib.patches import Polygon from matplotlib.collections import PatchCollection import matplotlib.pyplot as plt fig, 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()
Open Graph Description: 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 iss...
X Description: 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 iss...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/29952
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:5d93e4d1-609d-c112-3b70-62512327e09c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 98CC:383777:3AD4097:519FA6A:6A4F46D6 |
| html-safe-nonce | c6cde4f53a0f31ebd30705706c372fd09fa822ba5288381e6b6f532e2f50b2d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OENDOjM4Mzc3NzozQUQ0MDk3OjUxOUZBNkE6NkE0RjQ2RDYiLCJ2aXNpdG9yX2lkIjoiNjQzOTgxNjg3MjQwNTcxNDY0NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ecb2e19c65ac626c884c7c668744d43eef3daac58c1f581836a8a646c85b337e |
| hovercard-subject-tag | pull_request:2470396070 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/29952/files |
| twitter:image | https://avatars.githubusercontent.com/u/147451593?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/147451593?s=400&v=4 |
| og:image:alt | 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 iss... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width