I'm having some issues in trying to make an animation with Mayavi
In particular, below you may find a code for solving a classical Lorenz System, which I can easily plot.
I would like to create an animation and show the state evolution to some students as it changes over time, by using
mlab.plot3d
When I run the code, I can see that I'm not able to update the animation.
I have already checked e.g. the solution in https://github.com/enthought/mayavi/issues/696.
but I didn't manage to go very far. Could you please help me to figure out what I should change?
Thanks in advance,
Best regards,
Stefano
from __future__ import absolute_import, division, print_function
import numpy as np
from scipy.integrate import odeint
from mayavi import mlab
import moviepy.editor as mpy
rho = 28.0
sigma = 10.0
beta = 8.0 / 3.0
def f(state, t):
x, y, z = state # Unpack the state vector
return sigma * (y - x), x * (rho - z) - y, x * y - beta * z # Derivatives
state0 = [1.0, 1.0, 1.0]
t = np.arange(0.0, 40.0, 0.01)
dim_t = len(t)
states = odeint(f, state0, t)
x, y, z = states[:, 0], states[:, 1], states[:, 2]
mlab.plot3d(0,0,0,0)
trajectory = mlab.plot3d(x, y, z, t, colormap='hot', tube_radius=None)
@mlab.animate(delay=100)
def anim():
f = mlab.gcf()
while True:
for (i, j, k, w) in zip(x, y, z, t):
print('Updating scene...')
trajectory.mlab_source.set(i=i, j=j, k=k, w=w)
yield
anim()
mlab.show()
Hello :)
I'm having some issues in trying to make an animation with Mayavi
In particular, below you may find a code for solving a classical Lorenz System, which I can easily plot. I would like to create an animation and show the state evolution to some students as it changes over time, by using
mlab.plot3d
When I run the code, I can see that I'm not able to update the animation.
I have already checked e.g. the solution in https://github.com/enthought/mayavi/issues/696. but I didn't manage to go very far. Could you please help me to figure out what I should change?
Thanks in advance,
Best regards,
Stefano