1""" 2====== 3Timers 4====== 5 6Simple example of using general timer objects. This is used to update 7the time placed in the title of the figure. 8""" 9import matplotlib.pyplot as plt 10import numpy as np 11from datetime import datetime 12 13 14def update_title(axes): 15 axes.set_title(datetime.now()) 16 axes.figure.canvas.draw() 17 18fig, ax = plt.subplots() 19 20x = np.linspace(-3, 3) 21ax.plot(x, x ** 2) 22 23# Create a new timer object. Set the interval to 100 milliseconds 24# (1000 is default) and tell the timer what function should be called. 25timer = fig.canvas.new_timer(interval=100) 26timer.add_callback(update_title, ax) 27timer.start() 28 29# Or could start the timer on first figure draw 30#def start_timer(event): 31# timer.start() 32# fig.canvas.mpl_disconnect(drawid) 33#drawid = fig.canvas.mpl_connect('draw_event', start_timer) 34 35plt.show() 36