Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[GUI] Preserve legend settings when regenerating in figure options - #32285

Open
yushuosun wants to merge 2 commits into
matplotlib:mainfrom
yushuosun:fix/qt-figureoptions-legend-state
Open

[GUI] Preserve legend settings when regenerating in figure options#32285
yushuosun wants to merge 2 commits into
matplotlib:mainfrom
yushuosun:fix/qt-figureoptions-legend-state

Conversation

@yushuosun

@yushuosun yushuosun commented Sep 4, 2026

Copy link
Copy Markdown

PR summary

When users click "(Re-)Generate automatic legend" in the Qt figure options editor, only ncols was preserved, so custom legend settings like location, bounding-box anchor, and style were silently lost.

Changes

  • Copy key legend settings before regenerating in figureoptions.figure_edit:
    • location, bbox anchor/transform, column count, title
    • spacing/style fields (numpoints, markerscale, scatterpoints, paddings, etc.)
    • frame and alignment settings (fancybox, frameon, framealpha, shadow, edge/face colors)
    • marker/line/text style via prop and title font properties
  • Add regression test test_figureoptions_preserves_legend_settings ensuring 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

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • Documentation complies with general and docstring guidelines

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.

Copilot AI lite review requested due to automatic review settings September 4, 2026 00:35
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

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.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment on lines +252 to +260
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)
Comment on lines +288 to +292
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,
@iccir

iccir commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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.

@yushuosun
yushuosun force-pushed the fix/qt-figureoptions-legend-state branch from 73daa7d to eb7ac54 Compare September 8, 2026 12:10
@yushuosun

Copy link
Copy Markdown
Author

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.

@yushuosun

Copy link
Copy Markdown
Author

I opened a refreshed PR against current main: #32325

@yushuosun
yushuosun force-pushed the fix/qt-figureoptions-legend-state branch from eb7ac54 to 3dbb6cb Compare September 12, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants