animation_blit_wx.py
来自「非原创。很好的python例子」· Python 代码 · 共 68 行
PY
68 行
# For detailed comments on animation and the techniqes used here, see# the wiki entry# http://www.scipy.org/wikis/topical_software/MatplotlibAnimationimport matplotlibmatplotlib.use('WXAgg')matplotlib.rcParams['toolbar'] = Noneimport wximport sysimport pylab as pimport matplotlib.numerix as nximport time# allow the user to disable the WXAgg accelerator from the command lineif '--no-accel' in sys.argv: import matplotlib.backends.backend_wxagg matplotlib.backends.backend_wxagg._use_accelerator(False)ax = p.subplot(111)canvas = ax.figure.canvas# create the initial linex = nx.arange(0,2*nx.pi,0.01)line, = p.plot(x, nx.sin(x), animated=True, lw=2)# for profilingtstart = time.time()blit_time = 0.0def update_line(*args): global blit_time if update_line.background is None: update_line.background = canvas.copy_from_bbox(ax.bbox) # restore the clean slate background canvas.restore_region(update_line.background) # update the data line.set_ydata(nx.sin(x+update_line.cnt/10.0)) # just draw the animated artist ax.draw_artist(line) # just redraw the axes rectangle t = time.time() canvas.blit(ax.bbox) blit_time += time.time() - t if update_line.cnt==200: # print the timing info and quit frame_time = time.time() - tstart print '200 frames: %.2f seconds' % frame_time print '200 blits: %.2f seconds' % blit_time print print 'FPS: %.2f' % (200/frame_time) print 'BPS: %.2f' % (200/blit_time) sys.exit() update_line.cnt += 1 wx.WakeUpIdle()update_line.cnt = 0update_line.background = Nonewx.EVT_IDLE(wx.GetApp(), update_line)p.show()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?