Skip to content

Draw RadioButtons using scatter to ensure circular buttons. #24455

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

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 14, 2022

To ensure backcompat without bothering the majority of users who don't actually access the .circles attribute, dynamically (and irreversibly) switch back to the old draw method (list of Circles) whenever that attribute is accessed for the first time (if ever).

https://matplotlib.org/stable/gallery/widgets/radio_buttons.html now looks like
test
Note that the buttons are now circular.

Closes #24428.

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

The fallback is very clever 👍.

To ensure backcompat without bothering the majority of users who don't
actually access the .circles attribute, dynamically (and irreversibly)
switch back to the old draw method (list of Circles) whenever that
attribute is accessed for the first time (if ever).
@drammock
Copy link

drammock commented Nov 17, 2022

What is the recommendation for those of us (MNE-Python) who do access the .circles property? AFAICT from the diff there isn't an alternative in the public API of RadioButtons after this PR (but maybe I'm not looking carefully enough?)

If it helps, here is an example of what we do with it:

https://github.com/mne-tools/mne-python/blob/e65e5e5b49a7cdc21fb42d4a92bca5bd7a4e4329/mne/viz/_mpl_figure.py#L1050-L1061

we actually access .circles ten times in that file; some of them are simple one-liners to get a button's color, others are more complex like the snippet above.

@QuLogic
Copy link
Member

QuLogic commented Dec 2, 2022

If I've understood what that code does, it appears that you set a radius so that the buttons are reasonably sized. And the second thing is setting specific edge colours for each radio? I think the former is something we should just do, and the latter (styling options) is a reasonable enhancement request if you want to open an issue?

@drammock
Copy link

drammock commented Dec 2, 2022

If I've understood what that code does, it appears that you set a radius so that the buttons are reasonably sized. And the second thing is setting specific edge colours for each radio? I think the former is something we should just do, and the latter (styling options) is a reasonable enhancement request if you want to open an issue?

Another thing we do is apply transforms to ensure buttons are circular. That part should go be able to be removed after this PR, but we'll still want to be able to set size and linewidth (on all buttons uniformly) and set color, edgecolor, and opacity (on each button individually). I've opened #24583 for the feature request.

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

Successfully merging this pull request may close these issues.

[Bug]: RadioButtons should be circular, not elliptic
7 participants