title: Matplotlib animation in tkinter doesn't stop looping
body: <p>I'v got this matplotlib animation running in tkinter, it works fine but it just never stops looping, when i press 'X' the window closes but i have to force shut it with the task manager.</p>
  
  <p>This is the example code of how i tried to set it up:</p>
  
  <pre><code>from matplotlib import pyplot as plt
  from matplotlib import animation
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  
  import tkinter as tk
  from tkinter import *
  
  class Grapher(tk.Tk): # inherit Tk()
      def __init__(self, *args, **kwargs):
          tk.Tk.__init__(self, *args, **kwargs)   
          tk.Tk.wm_title(self, "Quarantined-Grapher")
  
          self.fig = plt.figure()
          ax = plt.axes(xlim=(0,2), ylim=(0, 100))
  
          N = 4 # amount of lines
          self.lines = [plt.plot([], [])[0] for _ in range(N)]
  
          # give the figure and the root(which is self) to the "canvas"
          self.canvas = FigureCanvasTkAgg(self.fig, self)
          self.canvas.show()
          self.canvas.get_tk_widget().pack()
  
          anim = animation.FuncAnimation(self.fig, self.animate, init_func=self.init,
                                          frames=100, interval=1000, blit=True)
      def init(self):
          for line in self.lines:
              line.set_data([], [])
          return self.lines
  
      def animate(self, i):
          for j,line in enumerate(self.lines):
              line.set_data([0, 2], [10 * j,i]) # some trick to animate fake data.
          return self.lines
  
  app = Grapher()
  app.mainloop()
  </code></pre>
  
  <p>My guess is it might be the animation loop that never stops running, because only tkinter knows to stop?..</p>
  
  <p>Note: <em>I made a graph work before, but i was using the tkinter after() method clearing and recreating data points, but it used up to much resources that i had to remake it. This way is so that i don't have to delete/create 10-50K data points every second.</em></p>