title: 3D waves animation using Matplotlib 3D
body: <p>I'm a french student and I'm currently working on waves, I'm trying to animate a 3D plot of a wave but I'm not good enough in python. The first surface can be drawn with plt.show() but if in the loop I put plt.draw() I have no graphical output.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from mpl_toolkits.mplot3d import Axes3D
  from matplotlib import cm
  
  if 'qt' in plt.get_backend().lower():
      try:
          from PyQt4 import QtGui
      except ImportError:
          from PySide import QtGui
  
  fig = plt.figure()
  
  # PARAMETRES PHYSIQUES
  C = 0.05  #VIT ONDE 
  Lx = 6.0  #taille du domaine
  Ly = 6.0  #taille du domaine
  T = 5.0   #temps d'integration
  
  # PARAMETRES NUMERIQUES
  NX = 151  #nombre de points de grille
  NY = 101  #nombre de points de grille
  NT = 250  #nombre de pas de temps
  
  dx = Lx/(NX-2) #pas de grille (espace)
  dy = Ly/(NY-2) #pas de grille (espace)
  dt = T/NT      #pas de grille (temps)
  
  
  alpha=(C**2*dt**2/dx**2)
  
  
  # Pour la figure
  xx = np.zeros((NX,NY))
  yy = np.zeros((NX,NY))
  for i in np.arange(0,NX):
     for j in np.arange(0,NY):
        xx[i,j]=i*dx
        yy[i,j]=j*dy
  
  plt.ion()
  #ax = plt.gca(projection='3d')
  ax = fig.add_subplot(111, projection='3d')
  
  a=40.0
  
  #Initialisation
  ddU   = np.zeros((NX,NY))
  U_data = np.exp(-a*((xx-(float(Lx)/2))**2+(yy-(float(Lx)/2))**2))
  U_old= U_data.copy()
  U_new = np.zeros((NX,NY))
  
  surf = ax.plot_surface(xx,yy,U_data,vmin=-0.1,vmax=0.1,cmap=cm.jet,antialiased=False,linewidth=0,rstride=1,cstride=1)
  
  plt.show()
  
  # Boucle en temps
  for n in np.arange(0,NT):
     ddU[1:-1,1:-1] = (U_data[2:,1:-1]-2*U_data[1:-1,1:-1]+U_data[:-2,1:-1])/(dx**2) \
                    + (U_data[1:-1,2:]-2*U_data[1:-1,1:-1]+U_data[1:-1,:-2])/(dy**2)
  
     U_new[1:-1,1:-1]=2*U_data[1:-1,1:-1]-U_old[1:-1,1:-1] + alpha*ddU[1:-1,1:-1]
  
     toto=U_old
     U_old=U_data
     U_data=U_new
     U_new=toto
  
  # FIXED BC
  #   U_data[0,:]=0.0
  
  # REFLECTING BC
     U_data[0,:]=U_data[2,:]
     U_data[NX-1,:]=U_data[NX-3,:]
     U_data[:,0]=U_data[:,2]
     U_data[:,NY-1]=U_data[:,NY-3]
  
  # PERIODIC BC
  #   U_data[0,:]=U_data[NX-2,:]
  #   U_data[NX-1,:]=U_data[1,:]
  #   U_data[:,0]=U_data[:,NY-2]
  #   U_data[:,NY-1]=U_data[:,1]
  
     if (n%10==0):
       plotlabel= "N = " + str(n+1)
  
       ax.cla()
       surf = ax.plot_surface(xx,yy,U_data,vmin=-0.1,vmax=0.1,cmap=cm.jet,antialiased=False,linewidth=0,rstride=1,cstride=1)
       ax.set_zlim3d(-0.1,0.1)
  
       plt.draw()
  
       if 'qt' in plt.get_backend().lower():
          QtGui.qApp.processEvents()
  
  plt.show()
  </code></pre>
  
  <p>I need a 3D plot of a propagation wave, like this [<a href="http://www.youtube.com/watch?v=bYOeA6r8o-I%5d" rel="nofollow">http://www.youtube.com/watch?v=bYOeA6r8o-I]</a></p>