Title: Fix legend settings not preserved when regenerating in Qt dialog by M-ndak · Pull Request #31934 · matplotlib/matplotlib · GitHub
Open Graph Title: Fix legend settings not preserved when regenerating in Qt dialog by M-ndak · Pull Request #31934 · matplotlib/matplotlib
X Title: Fix legend settings not preserved when regenerating in Qt dialog by M-ndak · Pull Request #31934 · matplotlib/matplotlib
Description: Clone ncols, shadow, fancybox, framealpha, title, loc, mode, borderaxespad and bbox_to_anchor from the existing legend before regenerating, so custom legend state is not discarded. Closes #17775 PR summary When the "(Re-)Generate automatic legend" checkbox is used in the Qt figure options dialog, the existing code only preserved ncols and draggable. All other custom legend settings (shadow, fancybox, framealpha, title, loc, mode, borderaxespad, bbox_to_anchor) were silently discarded. This fix reads all relevant properties from the existing legend before calling axes.legend() again, so the regenerated legend matches the original state. Minimum reproducible example: import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.plot(range(5), label='a') ax.plot(range(3)[::-1], label='b') ax.legend(bbox_to_anchor=(0,1.02,1,0.2), loc="lower left", mode="expand", borderaxespad=0, ncols=3) plt.show() # Open figure options, tick "(Re)-generate legend", click OK # Legend settings are lost AI Disclosure Used Claude (Anthropic) to assist with identifying the correct attributes to read from the Legend object and to verify the fix via a test script. PR checklist "closes #17775" is in the body of the PR description new and changed code is tested [N/A] Plotting related features are demonstrated in an example [N/A] New Features and API Changes are noted with a directive and release note [N/A] Documentation complies with general and docstring guidelines
Open Graph Description: Clone ncols, shadow, fancybox, framealpha, title, loc, mode, borderaxespad and bbox_to_anchor from the existing legend before regenerating, so custom legend state is not discarded. Closes #17775 P...
X Description: Clone ncols, shadow, fancybox, framealpha, title, loc, mode, borderaxespad and bbox_to_anchor from the existing legend before regenerating, so custom legend state is not discarded. Closes #17775 P...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/31934
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:f2432cce-ab40-793f-affd-bfdb189b0635 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 84D6:288D43:11537D4:176B131:6A556DB1 |
| html-safe-nonce | 98b3409c74010a148ece1868041ad5993413fbab6de63c356b4bdf5c429522ca |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NEQ2OjI4OEQ0MzoxMTUzN0Q0OjE3NkIxMzE6NkE1NTZEQjEiLCJ2aXNpdG9yX2lkIjoiMzA2OTcxNDc4MTUyMTE0NTI2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d3bc4d34c76abff7e807c21d11ae718c2ff54dd0a1761264e1bce3d5ce5ebee9 |
| hovercard-subject-tag | pull_request:3909961490 |
| 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/31934/files |
| twitter:image | https://avatars.githubusercontent.com/u/173817593?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/173817593?s=400&v=4 |
| og:image:alt | Clone ncols, shadow, fancybox, framealpha, title, loc, mode, borderaxespad and bbox_to_anchor from the existing legend before regenerating, so custom legend state is not discarded. Closes #17775 P... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| 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 | a90bd2a4a25feb75544d06b89350dcf95d9c46e0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width