Skip to content

Add ability to toggle legend in the figure options dialog box#30128

Open
ritvi-alagusankar wants to merge 3 commits into
matplotlib:mainfrom
ritvi-alagusankar:add-ability-legend-toggle-figure-options
Open

Add ability to toggle legend in the figure options dialog box#30128
ritvi-alagusankar wants to merge 3 commits into
matplotlib:mainfrom
ritvi-alagusankar:add-ability-legend-toggle-figure-options

Conversation

@ritvi-alagusankar

@ritvi-alagusankar ritvi-alagusankar commented Jun 2, 2025

Copy link
Copy Markdown

PR summary

Added the ability to toggle legend in the figure options dialog box, solving issue #11109. Changes in the PR:

  • Added a "Legend visible" checkbox to the figure options dialog box.
  • Implemented the callback to toggle legend visibility based on the value of the checkbox.

PR checklist

@ritvi-alagusankar ritvi-alagusankar marked this pull request as ready for review June 2, 2025 12:34

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@ritvi-alagusankar ritvi-alagusankar changed the title feat: add ability to toggle legend in the figure options dialog box Add ability to toggle legend in the figure options dialog box Jun 3, 2025
@ritvi-alagusankar

Copy link
Copy Markdown
Author

@rcomer gentle ping to help review this PR, this will be my first contribution to matplotlib. Please let me know if there are any changes to be made :)

@rcomer

rcomer commented Jun 12, 2025

Copy link
Copy Markdown
Member

I’m sorry but I am not currently available for reviewing. I also am not familiar with this part of the library so it is unlikely I will review it when I am available again.

@story645

Copy link
Copy Markdown
Member

@ritvi-alagusanka please add some tests for your code. You may wanna look at the tests for similar features as a model

@ritvi-alagusankar

ritvi-alagusankar commented Jul 1, 2025

Copy link
Copy Markdown
Author

@story645 @melissawm I have added a test case for this feature. Could you please help review this PR

@melissawm melissawm moved this from Waiting for author to Needs review in First Time Contributors Jul 9, 2025
@YQ157

YQ157 commented Sep 19, 2025

Copy link
Copy Markdown

Hi, I noticed Codecov reported missing coverage on this PR.

Since I don’t have push access to the source branch, I opened a follow-up PR to add the missing tests: #30587.
It extends the test suite for the QtAgg figureoptions dialog (legend handling, mappables, etc.) to improve coverage.

This is actually my first open-source contribution — happy to start by helping here! 🎉
Maintainers may merge it directly or cherry-pick into this PR, whichever is preferred.

Thanks again for the original work!

@rcomer

rcomer commented Sep 23, 2025

Copy link
Copy Markdown
Member

Note that CodeCov failing is not necessarily a blocker to getting this PR merged.
https://matplotlib.org/devdocs/devel/development_workflow.html#automated-tests

@ritvi-alagusankar

Copy link
Copy Markdown
Author

2> Note that CodeCov failing is not necessarily a blocker to getting this PR merged. https://matplotlib.org/devdocs/devel/development_workflow.html#automated-tests

@rcomer Could you help review this PR :)

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I'm sceptical that the matplotlib core library should invest further into configuration GUI. It's a rabbit hole. Also, all needed API is public and stable, so that such GUIs can be developed to arbitrary complexity by third parties; see e.g. https://pylustrator.readthedocs.io/en/latest/.

)
for name, axis in axis_map.items()
]),
('Legend visible', axes.legend_ is not None),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS this does not work, because it does not cover the case of an existing legend with set_visible(False)

Comment on lines +261 to +263
# toggle legend visibility
if axes.legend_ is not None:
axes.legend_.set_visible(legend_visible)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an issue with this:
Let's say, we don't have a legend, then the checkbox "Legend visible" is unchecked.
If the user checks the box, surpisingly nothing will happen since, we don't have a legend.

Either we would need to generate a legend (not so great beacuse we'd need to assume the defaults, equivalent to a legend() call), or we'd have to deactivate the checkbox if no legend is available (not sure whether that is possible with the generic dialog concept).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Needs review

Development

Successfully merging this pull request may close these issues.

ENH: Add legend toggle to figure options dialog box

6 participants