[Bug]: RadioButtons should be circular, not elliptic #24428
Copy link
Copy link
Closed
Labels
Description
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 tallActual 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
Reactions are currently unavailable
Activity
timhoffm commentedon Nov 11, 2022
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.
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
RadioButtonGroupwidget and discourage (/deprecate?)RadioButtons.anntzer commentedon Nov 11, 2022
I think(?) you can prevent this with set_adjustable("datalim")?
timhoffm commentedon Nov 11, 2022
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 commentedon 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 commentedon 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 commentedon 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 commentedon Nov 15, 2022
Or maybe somebody want's to create a fancy CheckMarker class for this ☑️ 😀