You are reading an old version of the documentation (v1.5.3). For the latest version see

Matplotlib 2.0.0rc2 is available

Install the release candidate now!



This Page

event_handling example code: timers.pyΒΆ

[source code]

# Simple example of using general timer objects. This is used to update
# the time placed in the title of the figure.
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime

def update_title(axes):

fig, ax = plt.subplots()

x = np.linspace(-3, 3)
ax.plot(x, x*x)

# Create a new timer object. Set the interval to 100 milliseconds
# (1000 is default) and tell the timer what function should be called.
timer = fig.canvas.new_timer(interval=100)
timer.add_callback(update_title, ax)

# Or could start the timer on first figure draw
#def start_timer(evt):
#    timer.start()
#    fig.canvas.mpl_disconnect(drawid)
#drawid = fig.canvas.mpl_connect('draw_event', start_timer)

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