title: Interactive plot based on Tkinter and matplotlib
body: <p>Dear programmming communauty,</p>
  
  <p>I am trying to perform a "interactive plot" based on Tkinter and pylab.plot in order to plot 1D values. The abssissa are a 1D numpy array <code>x</code> and the ordonates values are in a multidimension array <code>Y</code>, eg.</p>
  
  <pre><code>import numpy
  x = numpy.arange(0.0,3.0,0.01)
  y = numpy.sin(2*numpy.pi*x)
  Y = numpy.vstack((y,y/2))
  </code></pre>
  
  <p>I want to display y or y/2 (the elements of Y matrix) according to x and change between them with 2 buttons left and right (in order to go to more complex cases). Usually I create some functions like the following to plot graphs.</p>
  
  <pre><code>import pylab
  def graphic_plot(n):
      fig = pylab.figure(figsize=(8,5))
      pylab.plot(x,Y[n,:],'x',markersize=2)
      pylab.show()
  </code></pre>
  
  <p>To add two buttons to change the value of <code>n</code>parameter, I have tried this without success :</p>
  
  <pre><code>import Tkinter
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  class App:
  def __init__(self,master):
      # Create a container
      frame = Tkinter.Frame(master)
      frame.pack()
      # Create 2 buttons
      self.button_left = Tkinter.Button(frame,text="&lt;",command=self.decrease)
      self.button_left.pack(side="left")
      self.button_right = Tkinter.Button(frame,text="&gt;",command=self.increase)
      self.button_right.pack(side="left")
      self.canvas = FigureCanvasTkAgg(fig,master=self)
      self.canvas.show()
  def decrease(self):
      print "Decrease"
  def increase(self):
      print "Increase"
  root = Tkinter.Tk()
  app = App(root)
  root.mainloop()
  </code></pre>
  
  <p>Can someone help me to understand how to perform such kind of feature ? Many thanks.</p>