Title: Apply requested bar style to legend entry of empty bar plots by yohaidajurno · Pull Request #31974 · matplotlib/matplotlib · GitHub
Open Graph Title: Apply requested bar style to legend entry of empty bar plots by yohaidajurno · Pull Request #31974 · matplotlib/matplotlib
X Title: Apply requested bar style to legend entry of empty bar plots by yohaidajurno · Pull Request #31974 · matplotlib/matplotlib
Description: PR summary Closes #21506. When bar() is called with empty data, no Rectangle patches are created, so the BarContainer has no child artist for the legend handler to copy style from. The legend entry therefore fell back to the default style and the first color of the cycle, instead of the requested color/alpha — inconsistent with how plot() and scatter() handle empty data. plt.bar([], [], color='red', alpha=0.3, label='x') plt.legend() # before: default blue swatch; after: red, alpha 0.3 Fix Stash a non-drawn sample Rectangle carrying the resolved style on the container, and let update_from_first_child fall back to it when the container has no children. PR checklist New regression test (test_empty_bar_chart_legend_handle_style) test_legend.py + bar tests pass locally; ruff clean Behavior-change note added under doc/api/next_api_changes/behavior/ 🤖 Generated with Claude Code
Open Graph Description: PR summary Closes #21506. When bar() is called with empty data, no Rectangle patches are created, so the BarContainer has no child artist for the legend handler to copy style from. The legend entry...
X Description: PR summary Closes #21506. When bar() is called with empty data, no Rectangle patches are created, so the BarContainer has no child artist for the legend handler to copy style from. The legend entry...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/31974
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a8055f75-ccd0-b61c-8413-5a0b8f43b735 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C4AC:273A67:330ACEF:45F6A79:6A54A8A2 |
| html-safe-nonce | fa9a2eaf2e730a11d86f2e8a92e93270798fd45e6de737f599a358141391f181 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNEFDOjI3M0E2NzozMzBBQ0VGOjQ1RjZBNzk6NkE1NEE4QTIiLCJ2aXNpdG9yX2lkIjoiMjEyNzIyNDczNTcyNTI5OTg3NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8c2b2926e8c011ab650afb95fe63f4231649f7ed157be3cab3a608c62fb0f96b |
| hovercard-subject-tag | pull_request:3964432123 |
| 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/31974/files |
| twitter:image | https://avatars.githubusercontent.com/u/192731219?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/192731219?s=400&v=4 |
| og:image:alt | PR summary Closes #21506. When bar() is called with empty data, no Rectangle patches are created, so the BarContainer has no child artist for the legend handler to copy style from. The legend entry... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f8cfff6384f62259baea531c7f58bc7040f8dd92 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width