I've been trying for hours to get the size and aspect ratio of a simple list of radio buttons correct with no success. Initially, import the modules:
import matplotlib.pyplot as plt
from matplotlib.widgets import RadioButtons
Then the actual radio buttons are created:
plt.figure()
rax = plt.axes([0.1, 0.1, 0.6, 0.6], frameon=True)
labels = [str(i) for i in range(10)]
radio = RadioButtons(rax, labels)
This results in oval-shaped radio buttons that are too big and therefore overlap with one another vertically.
If I use the 'aspect' parameter of plt.axes and set it to 'equal':
plt.figure()
rax = plt.axes([0.1, 0.1, 0.6, 0.6], frameon=True, aspect='equal')
labels = [str(i) for i in range(10)]
radio = RadioButtons(rax, labels)
Then I get actual circles for the radio buttons, but they are still too big.
If I reduce the height to 0.3 still using the 'aspect' parameter set to 'equal', I just get a smaller version of the previous result (smaller buttons but still overlapping in a smaller axes instance).
What I would really like to do is have a very narrow width and a large height, and still have round radio buttons that don't overlap:
plt.figure()
rax = plt.axes([0.1, 0.1, 0.2, 0.8], frameon=True)
labels = [str(i) for i in range(10)]
radio = RadioButtons(rax, labels)
But this generates vertically oval-shaped radio buttons:
How can I solve this problem?
plt.figure()
rax = plt.axes([0.1, 0.1, 0.6, 0.6], frameon=True ,aspect='equal')
labels = [str(i) for i in range(10)]
radios = RadioButtons(rax, labels)
for circle in radios.circles: # adjust radius here. The default is 0.05
circle.set_radius(0.02)
plt.show()
Then you will get the attached figure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With