Embedding an animated matplotlib in tk Embedding an animated matplotlib in tk tkinter tkinter

Embedding an animated matplotlib in tk


Here is an example, I added a button that will start animation:

import numpy as npimport matplotlibmatplotlib.use("TKAgg")import pylab as plfig, ax = pl.subplots()p = 0x = np.linspace(0, 10, 200)y = np.sin(x+p)line, = ax.plot(x, y)canvas = fig.canvas.get_tk_widget()from Tkinter import Buttondef anim():    global p    p += 0.04    y = np.sin(x+p)    line.set_data(x, y)    fig.canvas.draw()    canvas.after(50, anim)def go():    anim()b = Button(canvas.master, text="go", command=go)b.pack()pl.show()