Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. enter image description here

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. enter image description here

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: enter image description here

How can I solve this problem?

like image 375
evianpring Avatar asked Apr 09 '16 16:04

evianpring


1 Answers

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.enter image description here

like image 72
Hun Avatar answered Nov 05 '22 02:11

Hun