求助,当循环时,无法按其它按钮
self.axes.yaxis.set_major_locator( MultipleLocator(major_ticker) )
self.axes.yaxis.set_minor_locator( MultipleLocator(minor_ticker) )
def legend(self,*args,**kwargs):
''' #图例legend for the plotting '''
self.axes.legend(*args,**kwargs)
def xlim(self,x_min,x_max):
''' # 设置x轴的显示范围 '''
self.axes.set_xlim(x_min,x_max)
def ylim(self,y_min,y_max):
''' # 设置y轴的显示范围 '''
self.axes.set_ylim(y_min,y_max)
def savefig(self,*args,**kwargs):
''' #保存图形到文件 '''
self.Figure.savefig(*args,**kwargs)
def cla(self):
''' # 再次画图前,必须调用该命令清空原来的图形 '''
self.axes.clear()
self.Figure.set_canvas(self.FigureCanvas)
self.UpdatePlot()
def ShowHelpString(self,HelpString="Show Help String"):
''' #可以用它来显示一些帮助信息,如鼠标位置等 '''
self.StaticText.SetLabel(HelpString)
################################################################
###############################################################################
# MPL_Frame添加了MPL_Panel的1个实例
###############################################################################
class MPL_Frame(wx.Frame):
"""MPL_Frame可以继承,并可修改,或者直接使用"""
def __init__(self,title="MPL_Frame Example In wxPython",size=(800,500)):
wx.Frame.__init__(self,parent=None,title = title,size=size)
self.MPL = MPL_Panel_base(self)
#创建FlexGridSizer
self.FlexGridSizer=wx.FlexGridSizer( rows=9, cols=1, vgap=5,hgap=5)
self.FlexGridSizer.SetFlexibleDirection(wx.BOTH)
self.RightPanel = wx.Panel(self,-1)
#测试按钮1
self.Button1 = wx.Button(self.RightPanel,-1,"TestButton",size=(100,40),pos=(10,10))
self.Button1.Bind(wx.EVT_BUTTON,self.Button1Event)
#测试按钮2
self.Button2 = wx.Button(self.RightPanel,-1,"AboutButton",size=(100,40),pos=(10,10))
self.Button2.Bind(wx.EVT_BUTTON,self.Button2Event)
#加入Sizer中
self.FlexGridSizer.Add(self.Button1,proportion =0, border = 5,flag = wx.ALL | wx.EXPAND)
self.FlexGridSizer.Add(self.Button2,proportion =0, border = 5,flag = wx.ALL | wx.EXPAND)
self.RightPanel.SetSizer(self.FlexGridSizer)
self.BoxSizer=wx.BoxSizer(wx.HORIZONTAL)
self.BoxSizer.Add(self.MPL,proportion =-10, border = 2,flag = wx.ALL | wx.EXPAND)
self.BoxSizer.Add(self.RightPanel,proportion =0, border = 2,flag = wx.ALL | wx.EXPAND)
self.SetSizer(self.BoxSizer)
#状态栏
self.StatusBar()
#MPL_Frame界面居中显示
self.Centre(wx.BOTH)
#按钮事件,用于测试
def Button1Event(self,event):
self.MPL.cla()#必须清理图形,才能显示下一幅图
x=np.arange(-10,10,0.25)
y=np.cos(x)
self.MPL.plot(x,y,'--*g')
self.MPL.xticker(3.0,1)
self.MPL.yticker(0.5,0.1)
self.MPL.title_MPL("MPL1")
self.MPL.ShowHelpString("You Can Show MPL Helpful String Here !")
self.MPL.grid()
self.MPL.UpdatePlot()#必须刷新才能显示
def Button2Event(self,event):
self.AboutDialog()
#自动创建状态栏
def StatusBar(self):
self.statusbar = self.CreateStatusBar()
self.statusbar.SetFieldsCount(3)
self.statusbar.SetStatusWidths([-2, -2, -1])
#About对话框
def AboutDialog(self):
self.MPL.cla()#必须清理图形,才能显示下一幅图
while 1:
x=np.arange(-10,10,0.25)
y=np.cos(x)
self.MPL.plot(x,y,'--*g')
self.MPL.xticker(2.0,0.5)
self.MPL.yticker(0.5,0.1)
self.MPL.title_MPL("MPL1")
self.MPL.ShowHelpString("You Can Show MPL Helpful String Here !")
self.MPL.grid()
self.MPL.UpdatePlot()#必须刷新才能显示
########################################################################
#主程序测试
if __name__ == '__main__':
app = wx.PySimpleApp()
frame =MPL_Frame()
frame.Center()
frame.Show()
app.MainLoop()