简体   繁体   中英

Matplotlib Radio Button Scaling

My starting point is the code from this link:

widgets example code: radio_buttons.py

All of the examples have a small number of radio buttons. I need more ie 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.

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

Instead of passing

('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.

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