Search code examples
pythonarraysmatplotlibplot

How do I create a 3D line plot in matplotlib from the data in arrays?


I have numerically solved the Lorenz equations using SciPy with the script:

# Lorenz Equations SciPy solver
import numpy as np
from scipy import integrate
from math import cos
from matplotlib import pyplot as plt
a, b = 0, 100
sigma, rho, beta = 10, 28, 8/3
N = 1000000
h = (b-a) / float(N)

def solvr(Y, t):
    return [sigma*(Y[1]-Y[0]), Y[0]*(rho-Y[2])-Y[1], Y[0]*Y[1]-beta*Y[2]]

t    = np.arange(a, b, h)
asol = integrate.odeint(solvr, [0, 1, 1], t)
x    = asol[:,0]
y    = asol[:,1]
z    = asol[:,2]

Now what I would like to do is plot x, y and z (which are all Numpy ndarrays, if you are unsure) against each other in a 3D line (or wireframe) plot. I think this would have to be done using matplotlib, but I am not picky, so long as you give me a solution that will plot the data in 3D I do not care what modules I need to import.


Solution

  • There is a brief example / tutorial on how to do wireframe plots (as well as 3d scatter) at the matplotlib site http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#wireframe-plots