0
好吧,所以我的一般問題是,我有一些數據集,一些好,一些壞。我想繪製他們全部然後使用CheckButtons小部件來選擇數據集。然後,我將對這些數據集進行平均,並將返回進一步處理,並調用下一次數據加載。從matplotlib小部件返回結果
基本上我有2個曲線圖可調用與g
f
和一個具有兩個軸(與數據將被平均)和第二表示的當前選中的複選框的平均值。然而,我需要在代碼中暫停,直到我對數據選擇感到滿意,並試圖使用matplotlib按鈕停止並返回當前的平均值。這是我很努力
s1,s2=Call.AVERAGE() #return the average of the checked lines
av1,=AX1.plot(x,s1)
av2,=AX1.plot(x,s2)
def func(label):
if Call.D[label]==1: #values with a D[label]==1 are averaged, 0 are ignored
Call.D[label]=0
elif Call.D[label]==0:
Call.D[label]=1
# every time a check box is changed the new average is calculated and plotted
s1,s2=Call.AVERAGE()
av1.set_ydata(s1)
av2.set_ydata(s2)
f.canvas.draw()
def end(event):
return #from this and outer function...
##code for check buttons
rax = g.add_axes([0.05, 0.3, 0.1, 0.3])
aq=append(Call.S1.keys(),Call.S2.keys())
check = CheckButtons(rax, aq, [True]*len(aq))
check.on_clicked(func)
##code for exit/save button
SAVE = f.add_axes([0.75, 0.02, 0.05, 0.025])
Sbutton = Button(SAVE, 'save')
Sbutton.on_clicked(end)
show()
return s1,s2 #only return from here after 'save' is clicked
我想只有當我很高興我的複選框的選擇,並點擊「保存」按鈕,從這個返回。
我已經嘗試了while
循環在返回前的代碼結束,但然後數字出現,但沒有軸/數據/按鈕。
希望這是有道理的,因爲它是從我的代碼中間粘貼的。感覺就像我剛剛錯過了一個簡單的解決方案。