查看示例和注释:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
N = 100 # number of points
x = np.arange(N, dtype=float) # x,y,z = 1d arrays
y = x * x
z = np.random.rand(N)
fig = plt.figure()
ax = fig.gca(projection='3d')
# you have to plot segments, its means your arguments
# have to be a slice of arrays like here: from x(i-1) to x(i) => x[i-1:i+1]
# to get color from colormap use index: 0 <= i <= 1
for i in xrange(1,N):
ax.plot(x[i-1:i+1], y[i-1:i+1], z[i-1:i+1], c = plt.cm.jet(1. * i / N))
plt.show()
在你的代码周期必须像:
for i in xrange(1,N):
ax3d.plot(matrix_array[i-1:i+1,0],matrix_array[i-1:i+1,1],matrix_array[i-1:i+1,2], color=pyplot.cm.jet(1.*i/N))