Ask Your Question
1

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

asked 2015-12-26 14:50:53 +0100

Fusion809 gravatar image

updated 2015-12-28 11:48:50 +0100

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-29 02:56:55 +0100 )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 08:05:08 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-01-03 02:30:27 +0100

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

Comments

While trying to run the same program I get the following error:"Arguement Z must be 2-dimensional." How do I change Z so that I can overcome this error?

loops gravatar imageloops ( 2019-04-14 10:45:34 +0100 )edit
0

answered 2015-12-28 09:32:32 +0100

slelievre gravatar image

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 10:49:42 +0100 )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 14:50:53 +0100

Seen: 2,092 times

Last updated: Jan 03 '16