title: Matplotlib Animated Subplots
body: <p>I'm trying to create matplotlib subplots that animate as live data comes in (within the larger framework of a tkinter python application). I was able to get the animation function working correctly with normal plots, but then when I modified the code for subplots, the behaviour became strange -- a large number of windows would open up at once, with only one of the subplots populated.</p>
  <pre><code>def showAnimatedValues():
      ani = FuncAnimation(plt.gcf(), animate, 2000)
      plt.show()
  
  def animate(self,analyzed=False):
      alldates = []
      alldata=[]
  
      for device_data in fetched:
          data=[]
          dates=[]
          for tup in device_data:
              if analyzed:
                  global device
                  device=str(tup[0])
                  data.append(data_analysis(float(tup[1])))
              else:
                  data.append(float(tup[1]))
              date=tup[2]
              formatted_date=reverse_formatter(date)
              formatted_date-=timedelta(hours=4)
              dates.append(str(formatted_date))
          alldates.append(dates)
          alldata.append(data)
  
      if len(alldates)&gt;1:
  
          plt.cla()
          fig, axs = plt.subplots(len(alldates),squeeze=True)
          fig.suptitle('Raw Live Current Data for Selected Devices')
          for i in range(len(alldates)):
              axs[i].plot(alldates[i],alldata[i])
              axs[i].get_xaxis().set_visible(False)
              axs[i].set_title(str(devices[i]))
      
      else:
  
          plt.cla()
          plt.plot(alldates[0],alldata[0])
          plt.title('Raw Live Current Data for Selected Device')
          plt.title(str(devices[0]), loc='right')        
          plt.gca().axes.get_xaxis().set_visible(False)
  
  button1 = tk.Button(text='Fetch Data ', command=getValues)
  button2 = tk.Button(text='Plot Raw Data ', command=showValues)
  button3 = tk.Button(text='Plot Analyzed Data ', command=showAnalyzedValues)
  button4 = tk.Button(text='Plot Live Raw Data ', command=showAnimatedValues)
  button5 = tk.Button(text='Plot Live Analyzed Data ', command=showAnimatedAnalyzedValues)
  
  canvas1.create_window(300, 180, window=button1)
  canvas1.create_window(400, 180, window=button2)
  canvas1.create_window(520, 180, window=button3)
  canvas1.create_window(645, 180, window=button4)
  canvas1.create_window(780, 180, window=button5)
  </code></pre>