from scipy import integrate
from matplotlib import pyplot as pl,animation as an
from mpl_toolkits.mplot3d import Axes3D
def lorentz_deriv(params,t0,sigma=10.,beta=8./3,rho=28.):
return [sigma*(y-x),x*(rho-z)-y,x*y-beta*z]
x0=-15+30*np.random.random((N_trajectories,3))
x_t=np.asarray([integrate.odeint(lorentz_deriv,x0i,t) for x0i in x0])
ax=fig.add_axes([0,0,1,1],projection='3d'); ax.axis('off')
colors=pl.cm.jet(np.linspace(0,1,N_trajectories))
lines=sum([ax.plot([],[],[],'-',c=c) for c in colors],[])
pts=sum([ax.plot([],[],[],'o',c=c) for c in colors],[])
ax.set_xlim((-25,25)); ax.set_ylim((-35,35)); ax.set_zlim((5,55))
for line,pt in zip(lines,pts):
line.set_data([],[]); line.set_3d_properties([])
pt.set_data([],[]); pt.set_3d_properties([])
for line, pt, xi in zip(lines,pts,x_t):
line.set_data(x,y); line.set_3d_properties(z)
pt.set_data(x[-1:],y[-1:]); pt.set_3d_properties(z[-1:])
fig,animate,frames=500,interval=30,blit=True,save_count=1500)
writergif=an.PillowWriter(fps=15)
anim.save(f,writer=writergif)
fpath='https://sagecell.sagemath.org/kernel/'
fpath+=os.getcwd()[14:]+'/files/'
s1='<figure><embed type="image/gif" src="'
s2='animation.gif" width=600/></figure>'
No comments:
Post a Comment