Matplotlib单选按钮缩放 [英] Matplotlib Radio Button Scaling

查看:51
本文介绍了Matplotlib单选按钮缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的出发点是来自这个链接的代码:

My starting point is the code from this link:

widgets 示例代码:radio_buttons.py

所有示例都有少量单选按钮.我需要更多(即最多25个).我对代码进行了如下调整,并调整了轴的高度以容纳更多按钮:

All of the examples have a small number of radio buttons. I need more i.e. up to 25. I adapted the code as follows with an adjustment of axes height to accommodate more buttons:

rax = plt.axes([0.05, 0.1, 0.15, 0.7], axisbg=axcolor)
radio3 = RadioButtons(rax, ('B1', 'B2', 'B3', 'B4', 'B5','B6', 'B7', 'B8', 'B9', 'B10'))

但是按钮开始重叠,增加轴高度只会使它们变大,但不会纠正重叠.

However the buttons start to overlap, and increasing the axes height just makes them larger, but not correcting the overlap.

我可以通过创建单独的单选按钮组来获得我想要的外观,但随后我需要多个 on_clicked 回调函数.

I can get the appearance I want by creating separate radio button groups, but then I need multiple on_clicked callback functions.

所以问题是,我可以将单选按钮的大小调整为不重叠还是仅进行硬编码,而按钮的数量是一种边缘情况,可以扩展最初意图的限制?

So the question is, can I adjust the size of the radio buttons to not overlap or is it simply hard coded, and that number of buttons is an edge case that stretch the limits of what was originally intended?

推荐答案

您可以通过两个选项来控制文本和单选按钮

There are two options you can pass which control the text and radio buttons

labels
    A list of matplotlib.text.Text instances
circles
    A list of matplotlib.patches.Circle instances

而不是通过

('B1', 'B2', 'B3', 'B4', 'B5','B6', 'B7', 'B8', 'B9', 'B10')

如果您只关心文本,则将每个列表元素更改为类似的内容,

If you just care about the text then change each list element into something like,

matplotlib.text.Text(text='B1',fontproperties={'size':12})

如果您关心圆圈大小,请传递类似的内容

If you care about the circle sizes then pass something like,

circles = matplotlib.patches.Circle((0,0), radius=5)

我个人将让圈子自己处理,而只是更改文字.

I would personally let the circles handle themselves and just change the text.

这篇关于Matplotlib单选按钮缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆