2

I need to set height of the matplotlib widget, change alignment or change font but i don't know how.

Screenshots:

5 radio buttons: enter image description here

15 radio buttons: enter image description here

And here is the critical code part:

def evolvecallback_(self, notification):
    global i
    stats={}
    results=[]
    fitnesses=[]

    for code,fit in evolve(i):
        results.append(code)
        stats[str(fit)]=code
        fitnesses.append(str(fit))
    i+=1
    fig = plt.figure() 
    done=""

    if found():
        done=" - Solution found!"
        print "Done!"

    fig.canvas.set_window_title("Generation "+str(i)+". - Best migrating individuals"+done) 


    ax = plt.subplot(111)
    ax.set_title(stats[str(fitnesses[0])])
    l, = ax.plot(x, s0, lw=2, color='blue')
    plt.subplots_adjust(left=0.4)

    axcolor = 'lightgoldenrodyellow'
    rax = plt.axes([0.05, 0.7, 0.15, 0.15], axisbg=axcolor)

    radio = RadioButtons(rax, tuple(fitnesses))
    def change(label):
        hzdict = {}
        x = np.arange(-5.0, 5.0, 0.01)
        j=0
        for i in tuple(results):
            hzdict[fitnesses[j]]=eval(i)
            j+=1
        ax.set_title(stats[str(label)])
        ydata = hzdict[str(label)]
        l.set_ydata(ydata)
        plt.draw()
    radio.on_clicked(change)
    plt.show()
sodd
  • 12,482
  • 3
  • 54
  • 62

1 Answers1

2

This line sets where and how big the axes the radio buttons are drawn onto is:

rax = plt.axes([0.05, 0.7, 0.15, 0.15], axisbg=axcolor)

Change it to something like

rax = plt.axes([0.05, 0.3, 0.15, 0.5], axisbg=axcolor)

(doc)

To be clear, rax is just an axes object to which you are adding the radio button widgets to.

tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • Hi, I've got the same issue (and so does this person: http://stackoverflow.com/questions/23997920/matplotlib-radio-button-scaling). I think it might be a bug. I've tried adjusting the axis, `rax`, but to no avail. It just ends up weirdly distorting the radiobutton. Do you know of a solution/workaround? – Jean-Luc May 07 '15 at 14:49
  • @Jean-Luc Thanks for kicking me on this. This looks like it is an issue with how the buttons are made (drawn as circles) and the aspect ratio of the axes. – tacaswell May 11 '15 at 20:57
  • Yep! That's exactly what I was thinking. Do you know if this is a bug, or if there is some other way to do it that perhaps scales everything properly? Should I file a bug report or...? – Jean-Luc May 12 '15 at 04:48
  • Yes, please file a bug report, the buttons are not parameterized super well. – tacaswell May 12 '15 at 10:59
  • @tacaswell Do you know the answer to https://stackoverflow.com/questions/55095111/displaying-radio-buttons-horizontally-in-matplotlib – anand_v.singh Mar 11 '19 at 05:43