Matplotlib 2.0.0rc2 is available

Install the release candidate now!



This Page

event_handling example code: pong_gtk.pyΒΆ

[source code]

#!/usr/bin/env python

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)