title: Matplotlib FuncAnimation does not update the plot embedded in wx Panel
body: <p>I am trying to update a plot with serial data with matplotlib FuncAnimation. I am using the following example to embed the plot in a wx app. </p>
  
  <p><a href="https://stackoverflow.com/questions/10737459/embedding-a-matplotlib-figure-inside-a-wxpython-panel">Embedding a matplotlib figure inside a WxPython panel</a></p>
  
  <p>However, the plot is not updated and only the initial plot is displayed. <a href="https://i.stack.imgur.com/8hMCy.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8hMCy.jpg" alt="enter image description here"></a></p>
  
  <p>In fact, the update function is never executed which is checked with print statements in try and except blocks. You may see the script here.</p>
  
  <pre><code>import wx
  
  from matplotlib.figure import Figure as Fig
  from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
  from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar
  
  from collections import deque
  import serial
  import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  import matplotlib as mlp
  import numpy as np
  
  # Class that inherits wx.Panel. The purpose is to embed it into 
  # a wxPython App. That part can be seen in main()
  class Serial_Plot(wx.Panel):
      def __init__(self, parent, strPort, id=-1, dpi=None, **kwargs):
          super().__init__(parent, id=id, **kwargs)
          self.figure  = Fig(figsize=(20,20))
          self.ax = self.figure.add_subplot(111)
          self.canvas = FigureCanvas(self, -1, self.figure)
          self.plot_data, = self.ax.plot([1,2,3,4],[1,2,3,4])
  
          self.toolbar = NavigationToolbar(self.canvas)
          self.toolbar.Realize()
  
          sizer = wx.BoxSizer(wx.VERTICAL)
          sizer.Add(self.canvas, 1, wx.EXPAND)
          sizer.Add(self.toolbar, 0, wx.RIGHT | wx.EXPAND)
          self.SetSizer(sizer)
          self.Fit()
          # Serial communication
          self.ser = serial.Serial(strPort, 115200)
          # Serial data initialized as deque. The serial readings from arduino
          # are set to be one value per line.
          self.vals = deque()
          # matplotlib function animation
          anim = animation.FuncAnimation(self.figure, self.update, 
                                     interval=20)
          plt.show()
          self.close
      def update(self, i):
          try:
              print('trying')
              # read serial line
              data = float(self.ser.readline().decode('utf-8'))
              print(data)
              self.vals.append(data)
              # update plot data
              self.plot_data.set_data(range(len(self.vals)), self.vals)
          except:
              print('oops')
              pass
          return self.plot_data
  
      def close(self):
          # close serial
          self.ser.flush()
          self.ser.close()
  
  def main():
  
      app = wx.App(False)
      frame = wx.Frame(None, -1, "WX APP!")
      demo_plot = Serial_Plot(frame,'COM3')
      frame.Show()
      app.MainLoop()
  
  if __name__ == "__main__":
      main()
  </code></pre>