2013-04-17 82 views
0

im matplotlib中的新增功能,並有一些困難時期。從用戶的角度來看,一切正常。 我有一個按鈕的窗口。按下按鈕會彈出一個新窗口,顯示該圖。玩完 後,我點擊X關閉此窗口。再次點擊X按鈕關閉窗口。 但我沒有退回到免費的提示。主窗口已鎖定並仍在後臺運行。關閉繪圖窗口後,該過程繼續運行

在這裏做了代碼的重要組成部分:

import matplotlib 
import matplotlib.pyplot as Plt 
from matplotlib.figure import Figure 

class MainPanel(wx.Panel): 

    def __init__(self, parent): #=None 

     wx.Panel.__init__(self, parent) 

         .... wxpython stuff goes here.... 

       self.btn1.Bind(wx.EVT_BUTTON, self.cplot) 

         .... 

    def cplot(self, event): 
     self.new = NewWindow(self) 
     self.new.cidadeplot(self) 
     self.new.Show() 
     return 


class NewWindow(wx.Frame): 

    def __init__(self,event): 
     wx.Frame.__init__(self, None, -1, 'Plot', size=(556, 618)) 
     wx.Frame.CenterOnScreen(self) 
     self.Bind(wx.EVT_CLOSE, self.OnClose) 


    def OnClose(self,event): 
     self.Destroy() 


    def cidplot(self,event): 


     self.fig = Figure() 

     self.axes = self.fig.add_subplot(111) 
     self.canvas = FigCanvas(self, -1, self.fig) 

     self.axes.set_ylabel("Parts") 
     self.axes.set_ylim(0,100) 
     self.axes.grid(True) 

     ....more axes settings... 

     bars = self.axes.bar(left=self.ii, height=self.tt, width=0.2, align='center', alpha=0.8) 

     .... 

     self.canvas.draw() 

     Plt.savefig("Parts.pdf", dpi=300) 



class MainFrame(wx.Frame): 

    def __init__(self): 

     wx.Frame.__init__(self, None, title = "System Test") 

     self.SetSize((556, 618)) 

     panel = MainPanel(self) 

     self.Show() 


if __name__ == "__main__": 

    app = wx.App(False) 
    frame = MainFrame() 
    app.MainLoop() 

我認爲這個問題是在self.fig =圖()(同樣的情況,如果我使用Plt.figure())

Im做當我創建一個新窗口或者在我的matplotlib部分時出錯了? 一些更好的方法來做到這一點?

在此先感謝。任何意識都是值得歡迎的。

回答

1

不要導入pyplot,它有它自己的包裝來處理管理圖形gui框架(除了狀態機界面)是pyplot的主要點。要做到這一點,它啓動它自己的主循環,這可能是你搞砸了。

確保你看看例子here

0

使用此功能的OnClose:

def onClose(self, event): 
    """""" 
    self.Close(True) 
0

Tcaswell是正確的。

我刪除了對pyplot的所有引用。 savefig鎖定了應用程序。 將所有更改爲self.axes.XXX和salf.fig.savefig(xxx)並工作。

謝謝。

相關問題