title: How to animate the figures in a Subplots?
body: <p>I have written a code to explain the Superposition of waves. I paste my <strong>Code</strong> and <strong>output</strong> below. But problem is I just only create <strong>static</strong> graph....Things become more interesting if I can animate the waves (in my code :<code>subplot(211)</code>) and the correspoding result in <code>subplot(212)</code>. But till now I can only animate without subplots...and when I researched on internet about "animating in subplots using <code>matplotlib</code>" the results I found not so understandable to me and also different from my code in this case. </p>
  
  <p>Can any one please help me in this regard? It would be better if the animation is based on my following code structure (of course the necessary change for subplot animation is appreciated). Thank you all.</p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>#Composition of Waves
  import matplotlib as mpl
  mpl.rc('text', usetex = True)
  mpl.rc('font', family = 'serif')
  import matplotlib.pyplot as plt
  import numpy as np
  
  plt.gca().set_aspect('equal', adjustable='box')
  plt.style.use(['ggplot','dark_background'])
  
  title = 'Composition of Waves'
  #Parameters:
  #a=Amplitude; w=Angular Frequency; phi = Phase Angle.
  
  #Definition of the function:
  def f(t,a,w,phi): 
      y = a*np.sin(w*t + phi)
      return y
  
  t = np.arange(0,4*np.pi,0.001)
  
  def create_plot(ptype):
      y1 = f(t,1,1,1)
      y2 = f(t,2,2,2)
      y = y1 + y2
      if ptype == 'waves':
          plt.plot(t, y1, label='$y=f_1(t)$')
          plt.plot(t, y2, label='$y=f_2(t)$')
      elif ptype == 'composition':
          plt.plot(t, y, label='$Composition$', color= 'm')
  
  plt.figure(1)
  plt.subplot(211)                                  
  create_plot('waves')
  plt.legend()
  plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
  #plt.xlabel('$x$')
  plt.ylabel('$y$')
  plt.title(title)
  
  plt.subplot(212)
  create_plot('composition')
  plt.legend()
  plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
  plt.xlabel('$t$')
  plt.ylabel('$y$')
  
  # Tweak spacing between subplots to prevent labels 
  from overlapping
  plt.subplots_adjust(hspace=0.5)
  
  plt.savefig('composition_Waves.eps', format='eps', dpi=1000,bbox_inches='tight')
  
  plt.show()
  </code></pre>
  
  <p><strong>Output</strong>
  <a href="https://i.stack.imgur.com/dPqv5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dPqv5.png" alt="Code Output"></a></p>
  
  <p>Here I want to animate the waves in different <code>w</code> and <code>phi</code>.</p>