简体   繁体   English

如何调整 matplotlib 单选按钮的大小和纵横比?

[英]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.axes 的 'aspect' 参数并将其设置为 '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).如果我仍然使用设置为“相等”的“方面”参数将高度降低到 0.3,我只会得到先前结果的较小版本(较小的按钮但仍然在较小的轴实例中重叠)。

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.然后你会得到附图。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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