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部分時出錯了? 一些更好的方法來做到這一點?
在此先感謝。任何意識都是值得歡迎的。