animation_blit_fltk.py

来自「非原创。很好的python例子」· Python 代码 · 共 53 行

PY
53
字号
import sysimport fltkimport matplotlibmatplotlib.use('FltkAgg')import pylab as pimport matplotlib.numerix as nximport time# save the clean slate background -- everything but the animated line# is drawn and saved in the pixel buffer backgroundclass animator:    def __init__(self,ax):        self.ax=ax        self.canvas=ax.figure.canvas        self.canvas.mpl_connect('draw_event',self.clear)        self.cnt=0        self.background=None        # for profiling        self.tstart = time.time()    def clear(self,event):        self.background = self.canvas.copy_from_bbox(self.ax.bbox)       def update(self,ptr):        # restore the clean slate background        if self.background is None:            self.background = self.canvas.copy_from_bbox(self.ax.bbox)          self.canvas.restore_region(self.background)        # update the data        line.set_ydata(nx.sin(x+self.cnt/10.0))          # just draw the animated artist        self.ax.draw_artist(line)        # just redraw the axes rectangle        self.canvas.blit(ax.bbox)         self.cnt+=1        if self.cnt==200:            # print the timing info and quit            print 'FPS:' , 200/(time.time()-self.tstart)            sys.exit()        return Trueax = p.subplot(111)# create the initial linex = nx.arange(0,2*nx.pi,0.01)line, = p.plot(x, nx.sin(x), animated=True)p.draw()anim=animator(ax)    fltk.Fl.add_idle(anim.update)fltk.Fl.run()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?