Temporizadores #

Exemplo simples de uso de objetos timer gerais. Isso é usado para atualizar o tempo colocado no título da figura.

Observação

Este exemplo exercita os recursos interativos do Matplotlib e isso não aparecerá na documentação estática. Por favor, execute este código em sua máquina para ver a interatividade.

Você pode copiar e colar partes individuais ou baixar o exemplo inteiro usando o link na parte inferior da página.

temporizadores
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime


def update_title(axes):
    axes.set_title(datetime.now())
    axes.figure.canvas.draw()

fig, ax = plt.subplots()

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

# 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)
timer.start()

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

plt.show()

Galeria gerada por Sphinx-Gallery