ENH/MAINT: Improve legend handling in Qt figure options dialog#32015
ENH/MAINT: Improve legend handling in Qt figure options dialog#32015jhkr1 wants to merge 1 commit into
Conversation
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.
|
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. |
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
ncolsanddraggable. 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 positiontitle— legend title textframeon— whether to show the frameshadow— whether to draw a shadowedgecolor,facecolor,framealpha— frame appearanceProblem 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