Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting a simple 3d numpy array using matplotlib

I want to plot the result of a numerical method for a three dimensional system of ODEs. My output is in the form (let's suppose we have computed three steps):

import numpy as np
v= np.array([[1,2,3], [4,5,6], [7,8,9]])

Where the first value in every 3-tuple is the x coordinate, the second is y coordinate and the third is the z coordinate.

I would like the most simple and efficient way of plotting these points on a 3D grid. The problem seems to be that the data should be formated like np.array([[1,4,7], [2,5,8], [3,6,9]]).

like image 619
D1X Avatar asked Oct 31 '16 21:10

D1X


1 Answers

You can plot the result in 3D like this:

import matplotlib.pyplot as plt, numpy as np
from mpl_toolkits.mplot3d import Axes3D

v= np.array([[1,2,3], [4,5,6], [7,8,9]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(v[:,0],v[:,1],v[:,2])
plt.show()

enter image description here

like image 124
Angus Williams Avatar answered Sep 19 '22 23:09

Angus Williams