Matplotlib小部件许多单选按钮发出

2024-10-04 03:26:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要设置matplotlib小部件的高度,更改对齐方式或更改字体,但我不知道如何设置。在

屏幕截图:

5个单选按钮: enter image description here

15个单选按钮: enter image description here

下面是关键代码部分:

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()

Tags: titlestatscodepltax按钮resultslabel
1条回答
网友
1楼 · 发布于 2024-10-04 03:26:30

该行设置单选按钮绘制到的轴的位置和大小:

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

把它改成

^{pr2}$

{a1}

明确地说,rax只是一个axes对象,您要将单选按钮小部件添加到其中。在

相关问题 更多 >