Skip to content

ENH/MAINT: Improve legend handling in Qt figure options dialog#32015

Open
jhkr1 wants to merge 1 commit into
matplotlib:mainfrom
jhkr1:feat-legend-toggle
Open

ENH/MAINT: Improve legend handling in Qt figure options dialog#32015
jhkr1 wants to merge 1 commit into
matplotlib:mainfrom
jhkr1:feat-legend-toggle

Conversation

@jhkr1

@jhkr1 jhkr1 commented Jul 8, 2026

Copy link
Copy Markdown

Closes #17775
Closes #11109

PR summary

This PR addresses two related issues in the Qt figure options dialog, both concerning legend handling in lib/matplotlib/backends/qt_editor/figureoptions.py.

Problem 1 (#17775): Legend settings are lost when regenerating

When a user clicks "Re-generate automatic legend" in the figure options dialog, the code previously only restored ncols and draggable. Any other settings the user had configured — such as the legend title, position, frame style, shadow, or transparency — were silently discarded and reset to their defaults.

Fix: Before regenerating, the existing legend's properties are captured and passed to axes.legend() as keyword arguments:

  • loc — legend position
  • title — legend title text
  • frameon — whether to show the frame
  • shadow — whether to draw a shadow
  • edgecolor, facecolor, framealpha — frame appearance

Problem 2 (#11109): No way to hide the legend from the options dialog

There was no way to toggle legend visibility in the figure options dialog without fully deleting the legend. This was inconvenient when a legend obscured part of the plot.

Fix: A "Show legend" checkbox is added to the Axes tab. Its initial state reflects the current visibility of the legend. When unchecked, the legend is hidden (but not deleted), and it can be shown again by re-checking the box.

AI Disclosure

I used an AI assistant to help navigate the codebase and understand the structure of figureoptions.py. The implementation logic and final code were verified and understood by me before submission.

PR checklist

Closes matplotlib#17775: Clone additional legend properties (loc, title, frameon,
shadow, edgecolor, facecolor, framealpha) when regenerating the legend,
so that user-configured settings are not lost on Apply.

Closes matplotlib#11109: Add a 'Show legend' checkbox to the Axes tab, allowing
users to toggle legend visibility without deleting it.
@github-actions

github-actions Bot commented Jul 8, 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.

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.

clone more legend settings when regenerating in Qt figure options dialog ENH: Add legend toggle to figure options dialog box

1 participant