ENH: Add legend toggle to figure options dialog box
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:
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.
Wow, I didn't know about draggable(). Thanks! I wonder why it's disabled by default...
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.
The legend has a set_visible() method.
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?
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.
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!
@wuaster any progress on this? Is there a PR?
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
@mspacek Sorry, no there isn’t.
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!
Good first issue - notes for new contributors
This issue is suited to new contributors because it does not require understanding of the Matplotlib internals. To get started, please see our contributing guide.
We do not assign issues. Check the Development section in the sidebar for linked pull requests (PRs). If there are none, feel free to start working on it. If there is an open PR, please collaborate on the work by reviewing it rather than duplicating it in a competing PR.
If something is unclear, please reach out on any of our communication channels.
Relevant file to work on is here: https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/backends/qt_editor/figureoptions.py
Work to do:
- figure out how to add a "legend visible" checkbox
- implement the callback to toggle the legend visibility
I don't think we can fold this into the "(Re)generate legend" tick box, but you can probably adapt that code.
Despite my earlier comment, the main part of this is not something that we can easily test so "manual testing" will have to do for this work.
Good first issue because the code that needs to be changed is very isolated, but medium because you will have to understand and modify a declarative UI builder.
hey @tacaswell i would like to take on the issue if its still open for assignement
Hi @RohitP2005 you are welcome to submit a pull request for any issue, but we do not assign them. Please see our contributors’ guide: https://matplotlib.org/devdocs/devel/index.html
@tacaswell #30128 to add the ability to toggle the legend