Ask Your Question
1

How do I plot a 3D Lorenz attractor with x, y and z labels?

asked 2015-12-26 07:50:53 -0600

Fusion809 gravatar image

updated 2015-12-28 04:48:50 -0600

I have been attempting to perform a 3D wireframe plot of the solution to the Lorenz equations, which is stored in the variables X, Y and Z. This is what I am presently using (unsuccessfully I might add):

 # Plot the result
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import axes3d

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.figure(1)
plt.xlabel('X(t)')
plt.ylabel('Y(t)')
plt.zlabel('Z(t)')
axes3d.plot_wireframe(X,Y,Z)
plt.show()

How do I get this plot to work? I'm guessing you'll probably be able to guess that X, Y and Z are ndarrays, produced from this SageMath script:

x,y,z=var('x,y,z')

# Next we define the parameters
sigma=10
rho=28
beta=8/3

# The Lorenz equations
lorenz=[sigma*(y-x),x*(rho-z)-y,x*y-beta*z]

# Time and initial conditions
N=250000
tmax=250
h=tmax/N
t=srange(0,tmax+h,h)
ics=[0,1,1]
sol=desolve_odeint(lorenz,ics,t,[x,y,z],rtol=1e-13,atol=1e-14)
X=sol[:,0]
Y=sol[:,1]
Z=sol[:,2]
edit retag flag offensive close merge delete

Comments

1

Googling a bit, I found a nice blog post here

http://sagemath.blogspot.cl/2008/01/j...

vdelecroix gravatar imagevdelecroix ( 2015-12-28 19:56:55 -0600 )edit

Thanks, you wouldn't happen to know where I can find detailed documentation on line3d would ya? I've Googled it but I can't find anything better than this, which is pretty minimal (only one mention to line3d in the entire document).

Fusion809 gravatar imageFusion809 ( 2015-12-29 01:05:08 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-01-02 19:30:27 -0600

Fusion809 gravatar image

I have found the answer to this question (and it came out of this answer to a question of mine at StackOverflow) and it does, in fact, involve matplotlib. Here is the code required to plot the X, Y and Z ndarrays and provide the axes labels (the axes info I got from here):

# Plot the result
from mpl_toolkits.mplot3d import axes3d
from matplotlib import pyplot as plt
# Call the plot function if you want to plot the data
def plot():
    fig = plt.figure(1)
    ax = fig.add_subplot(111, projection='3d')
    ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
    ax.set_xlabel('X(t)')
    ax.set_ylabel('Y(t)')
    ax.set_zlabel('Z(t)')
    plt.show()

plot()

which produces the result:

edit flag offensive delete link more
0

answered 2015-12-28 02:32:32 -0600

Unless you really need to use matplotlib, why not just use Sage's parametric_plot3d?

http://doc.sagemath.org/html/en/refer...

edit flag offensive delete link more

Comments

Could you show me how to do this? I looked at the documentation and as I am not very experienced with SageMath it was not particularly helpful. I tried running parametric_plot3d((X,Y,Z),(t[0],t[N])) and it returned this error.

Fusion809 gravatar imageFusion809 ( 2015-12-28 03:49:42 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-12-26 07:50:53 -0600

Seen: 339 times

Last updated: Jan 02 '16