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

ENH: Add legend toggle to figure options dialog box #11109

Open
mspacek opened this issue Apr 23, 2018 · 10 comments
Open

ENH: Add legend toggle to figure options dialog box #11109

mspacek opened this issue Apr 23, 2018 · 10 comments

Comments

@mspacek
Copy link
Contributor

mspacek commented Apr 23, 2018

Feature request

It would be nice if the user could toggle display of the legend (if any) in the figure options dialog box. Currently, it's possible to edit curve labels and regenerate the legend, but not toggle the display of the legend. This would be especially useful because sometimes the legend can obscure parts of the plot.

Apologies if this has been discussed somewhere already. I couldn't find anything here in GH issues.

Matplotlib version

  • Operating system: Xubuntu 16.04
  • Matplotlib version: 2.2.2, installed from pip
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.5.2
  • Jupyter version (if applicable):
  • Other libraries:
@ImportanceOfBeingErnest
Copy link
Member

I would support this in general.
In the meantime, you can make your legend draggable if that it desired. plt.legend().draggable(). While this will not turn it on or off it allows the user to drag it somewhere else in the plot where it might not disturb. Only drawback: It's kind of hard to get it back at the exact same position where it originally was after dragging.

@mspacek
Copy link
Contributor Author

mspacek commented Apr 25, 2018

Wow, I didn't know about draggable(). Thanks! I wonder why it's disabled by default...

@wuaster
Copy link

wuaster commented Mar 23, 2020

I'd like to work on this issue. My interpretation of this feature would be to add a button to the toolbar to toggle the legend(s). My initial plan would be to set the alpha levels of the legend to 0/1 by pressing the button but there may be a better strategy. If anyone has any suggestions or corrections, do let me know.

@timhoffm
Copy link
Member

The legend has a set_visible() method.

@wuaster
Copy link

wuaster commented Apr 4, 2020

I've got the button to work and I can use it to toggle the legend on/off. For unit tests, I'm not sure how I would go about doing them. Since I want to stay consistent, I'm not sure how the other toolbar buttons/keypresses are tested. Is there an example of how I can write the tests? What I want to do is draw a figure with a legend, click the new toolbar button/press the toggle key, and then compare the figure afterward, how would I go about doing this?

@tacaswell
Copy link
Member

There are some examples of interactive tests in https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/tests/test_widgets.py . The way the interactive code works is that the GUI side of things generates an "event" which is then pushed through our callback machinery. It is possible to create those same events in the tests and push them through the machinery.

@github-actions
Copy link

github-actions bot commented May 5, 2023

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label May 5, 2023
@mspacek
Copy link
Contributor Author

mspacek commented May 5, 2023

@wuaster any progress on this? Is there a PR?

@oscargus
Copy link
Contributor

oscargus commented May 5, 2023

It is worth noting that although the dialog is created as part of the test, the callback where the settings are applied is currently not tested. Hence, one can maybe not expect that it will be feasible to test this as part of the test suite. (Although of course that would be really nice, but not really related to the issue.)

https://app.codecov.io/gh/matplotlib/matplotlib/blob/main/lib/matplotlib/backends/qt_editor/figureoptions.py

@wuaster
Copy link

wuaster commented May 5, 2023

@mspacek Sorry, no there isn’t.

@github-actions github-actions bot removed the status: inactive Marked by the “Stale” Github Action label May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants