Hello I want to have python contour animation.for example Every second a wave will be born from the center and spread to the periphery. But I only want it with the level [0.0, 0.8]
wave. The contour and color are OK, but the animation does not work well. If anyone can help me please? At the end I want something like this:
Does anyone know how to make the link between the time and my function? I already used time
module to generate every time the contour changes but it does not work.
%pylab nbagg
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation
import matplotlib.animation as animation
#### generate some x,y,z data ####
r = np.linspace(0,6, num=100)
phi = np.linspace(0, 2*np.pi, num=200)
R, Phi = np.meshgrid(r,phi)
x = R*np.cos(Phi)
y = R*np.sin(Phi)
z = R
##################################
fig, ax=plt.subplots()
def data(x,y,z,i):
x = R*np.cos(Phi)
y = R*np.sin(Phi)
z = R-i
return z
def draw(i):
Z = data(x,y,z,i)
colors=('y','b')
levels = [0.0,0.8]
contourf(x,y,z,colors=('b', 'b', 'b', 'b', 'b', 'b', 'b','b'))
contourf(x,y,Z,levels=levels,colors=('y', 'b', 'b', 'b', 'b', 'b', 'b','b'))
#colorbar()
def animate(i):
ax.clear()
draw(i)
return ax,
draw(0)
ani = animation.FuncAnimation(fig,animate,np.arange(1, 10, .1),interval=5, blit=True)
plt.show()