import matplotlib.animation as animation
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
import time

def generate(X, Y, phi):
    R = 1 - np.sqrt(X**2 + Y**2)
    return np.cos(2 * np.pi * X + phi) * R

wframe = None
xs = np.linspace(-1, 1, 50)
ys = np.linspace(-1, 1, 50)
X, Y = np.meshgrid(xs, ys)
Z = generate(X, Y, 0.0)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')


def update_wf(phi):
	Z = generate(X, Y, phi)
	global wframe
	oldcol = wframe
	wframe = ax.plot_wireframe(X, Y, Z)
	if oldcol is not None:
		ax.collections.remove(oldcol)

line_ani = animation.FuncAnimation(fig, update_wf, np.linspace(0, 360 / 2 / np.pi, 100), interval=10, repeat=False)
plt.show()