Quantcast
Channel: solem's vision blog
Viewing all articles
Browse latest Browse all 31

Multidimensional meshgrid with Python

$
0
0
Looking for an easy way to plot cubes in 3D I found NumPy's mgrid that can do meshgrid in any number of dimensions. The syntax is a bit confusing but once you understand the trick, it works.

Here's a simple example that creates points for a unit cube and plots the points.

from pylab import *
from numpy import *
from mpl_toolkits.mplot3d import axes3d

# create 3D points
x,y,z = mgrid[0:2,0:2,0:2]
xx = x.flatten()
yy = y.flatten()
zz = z.flatten()

# plot 3D points
fig = figure()
ax = fig.gca(projection='3d')
ax.plot(xx,yy,zz,'o')

show()



Viewing all articles
Browse latest Browse all 31

Trending Articles