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

Skip to content

clone more legend settings when regenerating in Qt figure options dialog #17775

Open
@tacaswell

Description

@tacaswell

Bug report

xref https://stackoverflow.com/questions/62602933/matplotlib-navigation-toolbar-resets-legendstyle

The logic to regenerate the legend in the Qt figure option window discards most of the custom state set on the legend.

Bug summary

The logic that regenerate the legend pulls only ncols and if the legend is draggable

if generate_legend:
draggable = None
ncol = 1
if axes.legend_ is not None:
old_legend = axes.get_legend()
draggable = old_legend._draggable is not None
ncol = old_legend._ncol
new_legend = axes.legend(ncol=ncol)
if new_legend:
new_legend.set_draggable(draggable)

but nothing else.

Code for reproduction

import matplotlib .pyplot as plt
fig, ax = plt.subplots()
ax.plot(range(5), label='a')
ax.plot(range(3)[::-1], label='b')
ax.legend(bbox_to_anchor=(0,1.02,1,0.2), loc="lower left", mode="expand", borderaxespad=0, ncol=3)
plt.show()

open the figure options, tick "(Re)-generate legend" and hit OK or apply

Actual outcome

The legend settings are discarded when the figure is re-generated

Expected outcome

The bbox_to_anchor, loc,... settings to be re-used.

Matplotlib version

  • Operating system: any
  • Matplotlib version: 3.2+
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg (any Qt5 backend)
  • Python version: Any

installed from source

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Mediumhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuesGood first issueOpen a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions