You are reading an old version of the documentation (v2.0.2). For the latest version see


This Page

event_handling example code: pong_gtk.pyΒΆ

[source code]

from __future__ import print_function

# For detailed comments on animation and the techniques used here, see
# the wiki entry
import time

import gobject

import matplotlib

import matplotlib.pyplot as plt
import pipong

fig, ax = plt.subplots()
canvas = ax.figure.canvas

def start_anim(event):
    # gobject.idle_add(animation.draw,animation)
    gobject.timeout_add(10, animation.draw, animation)

animation = pipong.Game(ax)
start_anim.cid = canvas.mpl_connect('draw_event', start_anim)

tstart = time.time()
plt.grid()  # to ensure proper background restore
print('FPS: %f' % animation.cnt/(time.time() - tstart))

Keywords: python, matplotlib, pylab, example, codex (see Search examples)