Skip to content
Closed
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
22 changes: 21 additions & 1 deletion 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()
]),
('Show legend', axes.legend_ is not None and axes.legend_.get_visible()),
('(Re-)Generate automatic legend', False),
]

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

for i, (name, axis) in enumerate(axis_map.items()):
axis_min = general[4*i]
Expand Down Expand Up @@ -248,14 +250,32 @@
if generate_legend:
draggable = None
ncols = 1
kwargs = {}
if axes.legend_ is not None:
old_legend = axes.get_legend()
draggable = old_legend._draggable is not None
ncols = old_legend._ncols
new_legend = axes.legend(ncols=ncols)
kwargs = {
'loc': old_legend._loc_real,
'title': old_legend.get_title().get_text(),
'frameon': old_legend.get_frame_on(),
'shadow': old_legend.shadow,
}

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

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Blank line contains whitespace Raw Output: message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/qt_editor/figureoptions.py" range:{start:{line:264 column:1} end:{line:264 column:17}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"blank-line-with-whitespace" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:264 column:1} end:{line:264 column:17}}}
# Clone frame properties if the frame exists
frame = old_legend.get_frame()
if frame is not None:
kwargs['edgecolor'] = frame.get_edgecolor()
kwargs['facecolor'] = frame.get_facecolor()
kwargs['framealpha'] = frame.get_alpha()

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

View workflow job for this annotation

GitHub Actions / ruff

[rdjson] reported by reviewdog 🐶 Blank line contains whitespace Raw Output: message:"Blank line contains whitespace" location:{path:"/home/runner/work/matplotlib/matplotlib/lib/matplotlib/backends/qt_editor/figureoptions.py" range:{start:{line:271 column:1} end:{line:271 column:13}}} severity:WARNING source:{name:"ruff" url:"https://docs.astral.sh/ruff"} code:{value:"blank-line-with-whitespace" url:"https://docs.astral.sh/ruff/rules/blank-line-with-whitespace"} suggestions:{range:{start:{line:271 column:1} end:{line:271 column:13}}}
new_legend = axes.legend(ncols=ncols, **kwargs)
if new_legend:
new_legend.set_draggable(draggable)

if axes.legend_ is not None:
axes.legend_.set_visible(show_legend)

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