title: Embedding a matplotlib animation into a tkinter frame
body: <p>For a project I am working on a simple harmonic motion simulator (How a mass oscillates over time). I have got the data produced correctly and already have a graph produced within a tkinter frame work. At the moment it only shows a static graph where my objective is to display the graph as an animation over time.</p>
  <p>So for ease sake I have created a mock up of the programme using the following code:</p>
  <pre><code>#---------Imports
  from numpy import arange, sin, pi
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  from matplotlib.figure import Figure
  import tkinter as Tk
  from tkinter import ttk
  import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  #---------End of imports
  
  fig, ax = plt.subplots()
  
  x = np.arange(0, 2*np.pi, 0.01)        # x-array
  line, = ax.plot(x, np.sin(x))
  
  def animate(i):
      line.set_ydata(np.sin(x+i/10.0))  # update the data
      return line,
  
  ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), interval=25, blit=False)
  #plt.show() #What I want the object in tkinter to appear as
  
  root = Tk.Tk()
  
  label = ttk.Label(root,text=&quot;SHM Simulation&quot;).grid(column=0, row=0)
  
  canvas = FigureCanvasTkAgg(fig, master=root)
  canvas.show()
  canvas.get_tk_widget().grid(column=0,row=1)
  
  Tk.mainloop()
  </code></pre>
  <p>This code will display the animation that I want in the tkinter frame work when the <code>plt.show()</code> is uncommented. I would like to be able to place that animation within the framework of tkinter.</p>
  <p>I have also been on the matplotlib website and viewed all of the animation examples and none of them have helped. I have also looked on <a href="https://stackoverflow.com/questions/21179971/embedding-an-animated-matplotlib-in-tk">Embedding an animated matplotlib in tk</a> and that has placed the tkinter button within pyplot figure, whereas I would like to place the figure within a tkinter frame.</p>
  <p>So just to clarify, I would like to be able to place the animation produced when <code>plt.show()</code> is uncommented in a tkinter frame, ie <code>root = tk()</code>.</p>