Skip to content

Add ability to toggle legend in the figure options dialog box #30128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/matplotlib/backends/qt_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
)
for name, axis in axis_map.items()
]),
('Legend visible', axes.legend_ is not None),
('(Re-)Generate automatic legend', False),
]

Expand Down Expand Up @@ -196,6 +197,7 @@
title = general.pop(0)
axes.set_title(title)
generate_legend = general.pop()
legend_visible = general.pop()

Check warning on line 200 in lib/matplotlib/backends/qt_editor/figureoptions.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/backends/qt_editor/figureoptions.py#L200

Added line #L200 was not covered by tests

for i, (name, axis) in enumerate(axis_map.items()):
axis_min = general[4*i]
Expand Down Expand Up @@ -256,6 +258,10 @@
if new_legend:
new_legend.set_draggable(draggable)

# toggle legend visibility
if axes.legend_ is not None:
axes.legend_.set_visible(legend_visible)

Check warning on line 263 in lib/matplotlib/backends/qt_editor/figureoptions.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/backends/qt_editor/figureoptions.py#L263

Added line #L263 was not covered by tests

# Redraw
figure = axes.get_figure()
figure.canvas.draw()
Expand Down
Loading