2014-12-01 57 views
0

好吧,所以我的一般问题是,我有一些数据集,一些好,一些坏。我想绘制他们全部然后使用CheckButtons小部件来选择数据集。然后,我将对这些数据集进行平均,并将返回进一步处理,并调用下一次数据加载。从matplotlib小部件返回结果

基本上我有2个曲线图可调用与gf和一个具有两个轴(与数据将被平均)和第二表示的当前选中的复选框的平均值。然而,我需要在代码中暂停,直到我对数据选择感到满意,并试图使用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循环在返回前的代码结束,但然后数字出现,但没有轴/数据/按钮。

希望这是有道理的,因为它是从我的代码中间粘贴的。感觉就像我刚刚错过了一个简单的解决方案。

回答

0

通过直到图中关闭,然后在def end():我可以调用close(f)close(f)这将随后与代码继续s1和s2返回当前值不具有上ioff()show()作用就像一个暂停交互式绘图。