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

Skip to content

Fix legend settings not preserved when regenerating in Qt figure options#31526

Closed
Jah-yee wants to merge 1 commit intomatplotlib:mainfrom
Jah-yee:fix-legend-settings-regeneration
Closed

Fix legend settings not preserved when regenerating in Qt figure options#31526
Jah-yee wants to merge 1 commit intomatplotlib:mainfrom
Jah-yee:fix-legend-settings-regeneration

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 18, 2026

Good day

When '(Re)-generate automatic legend' is checked in the Figure Options dialog, the regenerated legend previously only preserved 'ncols' and 'draggable' settings. Other important legend properties like 'bbox_to_anchor', 'loc', 'mode', and 'borderaxespad' were discarded.

This fix captures these additional properties from the existing legend (if present) and passes them to axes.legend(), preserving the user's intended legend appearance.

Before (only ncols preserved):

new_legend = axes.legend(ncols=ncols)

After (all key properties preserved):

legend_kwargs = {
    'ncols': ncols,
    'bbox_to_anchor': bbox_to_anchor,
    'loc': loc,
    'mode': mode,
    'borderaxespad': borderaxespad,
}
new_legend = axes.legend(**legend_kwargs)

Testing:

  • Verified that ncols, loc, mode, borderaxespad, and bbox_to_anchor are all correctly preserved when regenerating a legend with bbox_to_anchor=(0, 1.02, 1, 0.2), loc='lower left', mode='expand', borderaxespad=0, ncol=3
  • Verified that the no-legend case (first legend creation) still works correctly
  • Verified that legends without bbox_to_anchor or mode set still work correctly

Fixes #17775

Thank you for your attention. If there are any issues or suggestions, please leave a comment and I will address them promptly.

Warmly,
RoomWithOutRoof

When '(Re)-generate automatic legend' is checked in the Figure Options
dialog, the regenerated legend previously only preserved 'ncols' and
'draggable' settings. Other important legend properties like
'bbox_to_anchor', 'loc', 'mode', and 'borderaxespad' were discarded.

Now the code captures these additional properties from the existing
legend (if present) and passes them to axes.legend(), preserving the
user's intended legend appearance.

Fixes matplotlib#17775
@rcomer
Copy link
Copy Markdown
Member

rcomer commented Apr 18, 2026

This account is opening a lot of PRs in a short space of time so I assume they are automated.
https://github.com/pulls?q=is%3Apr+author%3AJah-yee+archived%3Afalse+

Closing the PR and blocking the account for a week per our policy
https://matplotlib.org/devdocs/devel/contribute.html#use-of-generative-ai

@rcomer rcomer closed this Apr 18, 2026
@melissawm melissawm added the ai-contribution PRs that are AI generated without a human in the loop label Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-contribution PRs that are AI generated without a human in the loop GUI: Qt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clone more legend settings when regenerating in Qt figure options dialog

3 participants