Nugroho's blog.: Lorenz Attractor 3D Scatter Plot using Python with Matplotlib

Pages

Wednesday, April 13, 2016

Lorenz Attractor 3D Scatter Plot using Python with Matplotlib


 After failed with regular plot() syntax, I have luck with the scatter() one, :)

"""
Cluster
"""
import numpy as np #untuk operasi array
import matplotlib.pyplot as plt #untuk gambar grafik
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation #untuk menggerakkan grafik
from itertools import cycle
randColor = cycle('bgrcmk').next
randMarker= cycle('.,ov^<>12348sp*hH+xDd|_').next

#fig, ax = plt.subplots()
fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')

x = 1.
y = 1.
z = 1.

ax.scatter(x, y, z )

def animate(i):
global x,y,z,n

dt = 1./64.
s = 10.
b = 8./3.
r = 28



xdot = s * (y-x)
ydot = x*r -x*z -y
zdot = x*y -b*z

x = x+xdot*dt
y = y+ydot*dt
z = z+zdot*dt


ax.scatter(x,y,z, c=randColor(), marker=randMarker())

ani = animation.FuncAnimation(fig, animate, frames=2000, interval=10, blit=False)
#ani.save('LorenzAtrractor3D.mp4',bitrate=1024)
plt.show()




.

 






No comments:

Post a Comment