[GUI] Preserve legend settings when regenerating in figure options - #32285
[GUI] Preserve legend settings when regenerating in figure options#32285yushuosun wants to merge 2 commits into
Conversation
|
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. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
There was a problem hiding this comment.
🟡 Changes recommended
The new regression test’s fedit mock returns data in a shape that does not match what apply_callback expects for curve settings, which will fail when the Axes has labeled lines.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the Qt figure options editor so that when users click “(Re-)Generate automatic legend”, it re-creates the legend while preserving key legend configuration (location/anchor, styling, spacing, frame, and font settings), and adds a regression test to ensure those settings are retained.
Changes:
- Preserve existing legend parameters (loc, bbox anchor/transform, spacing, frame styling, fonts, alignment, etc.) when regenerating the legend in
figureoptions.figure_edit. - Add a Qt backend regression test that exercises legend regeneration and asserts key properties remain unchanged.
File summaries
| File | Description |
|---|---|
| lib/matplotlib/backends/qt_editor/figureoptions.py | Copies legend settings from the existing legend into the regenerated legend. |
| lib/matplotlib/tests/test_backend_qt.py | Adds a regression test for preserving legend settings across regeneration. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def fake_fedit(datalist, **kwargs): | ||
| general = list(datalist[0][0]) | ||
| general[-1] = True | ||
| payload = [general] | ||
| if len(datalist) > 1: | ||
| payload.append(list(datalist[1])) | ||
| if len(datalist) > 2: | ||
| payload.append(list(datalist[2])) | ||
| kwargs["apply"](payload) |
| edgecolor=old_legend.legendPatch.get_edgecolor(), | ||
| facecolor=old_legend.legendPatch.get_facecolor(), | ||
| linewidth=old_legend.legendPatch.get_linewidth(), | ||
| alignment=old_legend._alignment, | ||
| prop=old_legend.prop, |
|
Thank you for your first pull request! Could you please add the missing sections from our Pull Request Template, specifically those regarding your use of AI. |
73daa7d to
eb7ac54
Compare
|
I updated the PR body to include the missing PR template sections (AI disclosure + quality checklist). Most checks are now complete; remaining failures are external services/AppVeyor/CircleCI waiting. If there are any in-repo review concerns, I can address them immediately. |
Signed-off-by: YushuoSun <[email protected]>
|
I opened a refreshed PR against current main: #32325 |
eb7ac54 to
3dbb6cb
Compare
PR summary
When users click "(Re-)Generate automatic legend" in the Qt figure options editor, only
ncolswas preserved, so custom legend settings like location, bounding-box anchor, and style were silently lost.Changes
figureoptions.figure_edit:numpoints,markerscale,scatterpoints, paddings, etc.)fancybox,frameon,framealpha,shadow, edge/face colors)propand title font propertiestest_figureoptions_preserves_legend_settingsensuring regenerated legend keeps those settings.Notes
No behavioral changes when
"(Re-)Generate automatic legend"is unchecked.AI Disclosure
OpenAI Codex assisted with the implementation, regression test, CI diagnosis, and PR description. The Qt test callback was corrected to use the form's returned field values.
PR quality check
Validation
GitHub Actions run 34357160189, for commit
3dbb6cbb0407fc3d424bff8f6660a261ccba1e41, reports passing Linux and macOS test jobs and lint checks. The ARM job was cancelled; the separate AppVeyor build failed and still needs investigation. The corrected code is being carried back to this original PR as requested by a maintainer.