title: continuously updating graph in tkinter
body: <p>I have the following python code (in PyCharm) that I use to take readings from an <code>Arduino</code> board. The readings themselves are fine. I have the two following problems with the tkinter part of the code:</p>
  
  <ol>
  <li>The code begins to read in values from Arduino as soon as it is
  launched, whereas I want to initiate this on a button click
  ('read_data'); as long as I don't press the 'read_data' button, the
  graph is not displayed, but readings are taken; I can see that when
  I open the graph several seconds after I begin running the code;</li>
  <li>When I close the plot <code>close_plot</code>, the graph window is indeed
  closed, only to be re-opened a short while later.</li>
  </ol>
  
  <p>I think the problem lies in <code>Top.after</code> as it is continuously run within the <code>mainloop()</code> and, therefore, the <code>read_data</code> function is continuously updated. How can I get around this?</p>
  
  <pre><code>import serial
  from tkinter import *
  from matplotlib import pyplot as plt
  
  Top = Tk()
  
  ser = serial.Serial('COM3', baudrate=9600, timeout=1)
  
  x = []
  y = []
  
  def read_data():
      plt.ion()
      new_value = ser.readline().decode('ascii')
      if new_value == '':
          pass
      else:
          y.append(eval(new_value[:-2]))
          x.append(len(y) - 1)
          plt.plot(x, y, 'r-')
          plt.show()
          plt.pause(0.0001)
          Top.after(100, read_data)
  
  def close_plot():
      plt.close()
      global x, y
      x = []
      y = []
  
  def quit():
      Top.destroy()
  
  Button(Top, text='Read', command=read_data).pack()
  Button(Top, text='Close plot', command=close_plot).pack()
  Button(Top, text='Quit', command=quit).pack()
  
  Top.after(100, read_data)
  mainloop()
  </code></pre>
  
  <p>Edit: when pressing the <code>read_data</code> button, I get the following warning: </p>
  
  <pre><code>C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backend_bases.py:2445: MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented warnings.warn(str, mplDeprecation)
  </code></pre>