Skip to content
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

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

Open
tacaswell opened this issue Jun 27, 2020 · 2 comments
Open
Labels
Difficulty: Medium Good first issue Open a pull request against these issues if there are no active ones!

Comments

@tacaswell
Copy link
Member

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

@tacaswell tacaswell added Difficulty: Medium Good first issue Open a pull request against these issues if there are no active ones! labels Jun 27, 2020
@tacaswell tacaswell added this to the needs sorting milestone Jun 27, 2020
@tacaswell
Copy link
Member Author

I am tagging this as good first issue because I think all of the changes required will be localized in the code snippet linked in the OP in figureoptions.py but medium difficulty because it will require reading and understanding the legend code enough to find and extract the relevant settings. I expect this to be tractable to someone who is comfortable reading Python but may not be a good choice for someone just learning.

@tacaswell
Copy link
Member Author

This can go in the next release once we have a volunteer to implement it :)

@tacaswell tacaswell modified the milestones: needs sorting, v3.4.0 Jul 1, 2020
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 27, 2021
@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Sep 25, 2021
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Jul 8, 2022
@QuLogic QuLogic modified the milestones: v3.7.0, future releases Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium Good first issue Open a pull request against these issues if there are no active ones!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants