Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: RadioButtons should be circular, not elliptic #24428

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

Closed
anntzer opened this issue Nov 11, 2022 · 7 comments · Fixed by #24455
Closed

[Bug]: RadioButtons should be circular, not elliptic #24428

anntzer opened this issue Nov 11, 2022 · 7 comments · Fixed by #24455

Comments

@anntzer
Copy link
Contributor

anntzer commented Nov 11, 2022

Bug summary

RadioButtons are drawn as Circles in transAxes space, which means that as soon as the containing Axes is not equal-aspect, they will actually be elliptical, not circular.
In order to fix this, either the parent axes must be forced to be equal-aspect (we already remove the ticks and the navigatability, so more configuration may be OK), or we should use add functionality to Circle so that the center and the radius can be in different transform systems (center in transAxes, radius in pixels) -- or abuse scatter() instead to draw the radiobuttons (but this would break the radiobuttons.circles attribute).

Code for reproduction

https://matplotlib.org/stable/gallery/widgets/radio_buttons.html
and make the window much wider than tall

Actual outcome

radio buttons are elliptical

Expected outcome

radio buttons stay circular

Additional information

No response

Operating system

fedora37

Matplotlib Version

3.7.0.dev619+g3d6c3da884

Matplotlib Backend

any

Python version

3.10

Jupyter version

ENOSUCHLIB

Installation

git checkout

@timhoffm
Copy link
Member

In order to fix this, either the parent axes must be forced to be equal-aspect

I don't think you should enforce an equal aspect of the Axes box. This would lead to scaling the height of the box when you change the width of the figure. This (i) not how GUI elements normally behave and (ii) can lead to vertical shrinking and thus vertical text overlap.

If you play the aspect game, I think it would need to be in data coordinates. - But that means, changing Circle and Text coords to data, which is technically a breaking change as well.

or abuse scatter()

Using markers may actually be a good idea because they are in (i think) points, so that they have a constant size just as the Text.


Either way, if compatibility is a concern, it may be a reasonable approach to create a new RadioButtonGroup widget and discourage (/deprecate?) RadioButtons.

@anntzer
Copy link
Contributor Author

anntzer commented Nov 11, 2022

This would lead to scaling the height of the box when you change the width of the figure.

I think(?) you can prevent this with set_adjustable("datalim")?

@timhoffm
Copy link
Member

This would lead to scaling the height of the box when you change the width of the figure.

I think(?) you can prevent this with set_adjustable("datalim")?

This will only affect the circle if you switch to specifying the circle in data coordinates. As long as the circle stays in axes coordinates, the datalims will happily scale beneath it without any visual effect.

@jklymak
Copy link
Member

jklymak commented Nov 11, 2022

Do the sliders change aspect when the figure is changed? These should be in figure physical units (points) shouldn't they?

@anntzer
Copy link
Contributor Author

anntzer commented Nov 12, 2022

Sliders cover an entire axes, so it comes down to how you specified the axes? But most likely (whether it's an add_subplot() or an add_axes()) they will indeed change aspect in that case.
Unless you're talking about the round "button" of the slider; that one stays circular, because it's actually drawn with plot(..., "o") (which is a more or less similar strategy to drawing with scatter -- for radiobuttons, the advantage of scatter is that it would easily allow one button to be selected and not the others, while keeping everything within a single artist).

@anntzer
Copy link
Contributor Author

anntzer commented Nov 15, 2022

Note that the same issue also affects CheckButtons, and from a quick try one can use a solution similar to #24455 (using two series of scatters, one with marker="s" and the other with marker="x", with the color varying on the latter); it may be a good idea to make that a good first issue once #24455 is merged, suggesting to take that PR as example of how to fix it.

@timhoffm
Copy link
Member

and the other with marker="x"

Or maybe somebody want's to create a fancy CheckMarker class for this ☑️ 😀

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

Successfully merging a pull request may close this issue.

3 participants