Sunday, 25 August 2013

How can i place matplotlib animation on tkinter canvas?

How can i place matplotlib animation on tkinter canvas?

I am trying to add the below animation to tkinter canvas. below animation
is matplotlib example. How can i place this animation on tkinter canvas
either by grid or pack methods. my final aim is to place a animated
contour on tkitner canvas.
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure(frameon=False)
def f(x, y):
return np.sin(x) + np.cos(y)
x = np.linspace(0, 2 * np.pi, 120)
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
# ims is a list of lists, each row is a list of artists to draw in the
# current frame; here we are just animating one artist, the image, in
# each frame
ims = []
for i in range(60):
x += np.pi / 15.
y += np.pi / 20.
im = plt.imshow(f(x, y),aspect='auto')
ims.append([im])
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,
repeat_delay=1000)
#ani.save('dynamic_images.mp4')
plt.show()
Thanks in advance

No comments:

Post a Comment