animation_blit_wx.py :  » Chart-Report » Matplotlib » matplotlib-0.99.1.1 » doc » mpl_examples » animation » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Chart Report » Matplotlib 
Matplotlib » matplotlib 0.99.1.1 » doc » mpl_examples » animation » animation_blit_wx.py
# For detailed comments on animation and the techniqes used here, see
# the wiki entry
# http://www.scipy.org/wikis/topical_software/MatplotlibAnimation

# The number of blits() to make before exiting
NBLITS = 1000

import matplotlib
matplotlib.use('WXAgg')
matplotlib.rcParams['toolbar'] = 'None'

import wx
import sys
import pylab as p
import numpy as npy
import time


# allow the user to disable the WXAgg accelerator from the command line
if '--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


p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs
p.grid() # to ensure proper background restore

# create the initial line
x = npy.arange(0,2*npy.pi,0.01)
line, = p.plot(x, npy.sin(x), animated=True, lw=2)

# for profiling
tstart = time.time()
blit_time = 0.0

def 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(npy.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 == NBLITS:
        # print the timing info and quit
        frame_time = time.time() - tstart
        print '%d frames: %.2f seconds' % (NBLITS, frame_time)
        print '%d blits:  %.2f seconds' % (NBLITS, blit_time)
        print
        print 'FPS: %.2f' % (NBLITS/frame_time)
        print 'BPS: %.2f' % (NBLITS/blit_time)
        sys.exit()

    update_line.cnt += 1
    wx.WakeUpIdle()



update_line.cnt = 0
update_line.background = None
wx.EVT_IDLE(wx.GetApp(), update_line)
p.show()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.