简体   繁体   中英

How do I adjust the size and aspect ratio of matplotlib radio buttons?

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. 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM