I tried to do a very simple animation and save it with matplotlib, but without success. I want for example to see something oscillating: here the best I could do
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
#Define x,y vectors and meshgrid with function u on it
x = np.arange(0,10,0.1)
y = np.arange(0,10,0.1)
X,Y = np.meshgrid(x,y)
u = np.sin(X + Y)
#Create a figure and an axis object for the surface
#(which by the way is not initialized, because I don't know were to)
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
#Define a kind-of animation function, imitating what I saw many times
def animate(n):
global u
for n in (1,20):
u = np.sin((X + Y)*n)
return fig,
#I'm missing many commands, I'm just putting what I know
anim = animation.FuncAnimation(fig,animate)
anim.save('A.mp4',fps=10)
I read tons of online documentation, including the official one, but I cannot find a clear example in which a surface evolve with time. I also find very difficult to grasp the logic behind the construction of plots with matplotlib (I read about figures, objects associated, axes, other objects... I get confused), but I'm also self-learning it for an exam and I'm not really a tech guy, so maybe that's why I'm having so much troubles; fundamentally, if you answer and can spend two more minutes describing in some more detail what you're doing, you'll make me very happy. Many thanks for any help.