6

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?

evianpring
  • 3,316
  • 1
  • 25
  • 54

2 Answers2

6
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

Hun
  • 3,707
  • 2
  • 15
  • 15
  • 1
    Still one more question: it seems that all the examples that work out nicely use the same width and height in the rectangle that is passed to plt.axes (in your case that value was 0.6). But I'd like to have the same result you got, with a narrow width. Say, 0.1 width and 0.6 height. How can I do this without the distortions? – evianpring Apr 09 '16 at 18:03
  • The reason I ask is that these radio buttons will be a narrow sidebar to a plot on its right. So it should be narrow but tall. This, for example doesn't work: plt.figure() rax = plt.axes([0.1, 0.1, 0.2, 0.60], frameon=True) 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) Though it once again looks nice but not exactly what I want if I use aspect='equal' – evianpring Apr 09 '16 at 18:08
  • For that I need to look up the source code. Why don't you post that specific question? It has something to do with axis not radio button. Someone may jump in and answer. – Hun Apr 09 '16 at 18:13
  • New question: http://stackoverflow.com/questions/36520864/how-do-i-get-narrow-width-and-a-large-height-on-a-radiobuttons-widget-and-still – evianpring Apr 09 '16 at 18:21
0

I found the right snippet in here thanks to @evianpring How do I get narrow width and a large height on a RadioButtons widget, and still have round radio buttons that don't overlap?

MaxBlax360
  • 1,070
  • 1
  • 12
  • 15