I'm using matplotlib to plot some data as 2D curves in a 3D axes. 开发者_开发知识库I use the ax = axes3d.Axes3D()
to define my axes and ax.plot(x, y, zs='z')
to plot my 2D curves in the 3D space.
Now I want to add something that looks like what is on this page http://matplotlib.sourceforge.net/examples/mplot3d/polys3d_demo.html, but I want to enter directly the coordinates of the vertex. In this example they have a fixed z
array and they plot polygons with vertices (x,y)
, whereas what I want is z(x)
and (x,y)
vertices. Does anyone know how to do something like this?
And actually I don't need the collection thing, I just want to plot one big square in an arbitrary direction.
I tried to simply enter the coordinates and use ax.plot()
:
verts = np.array([[0,0,0], [0,1,0], [1,1,1], [1,0,1], [0,0,0]])
ax.plot(verts[:,0], verts[:,1], verts[:,2], zdir='y')
and it indeed plots a square, but I can't (or don't know how to) fill the face.
I hope this is what you wanted!
My rectangle will go from 0 to 10. So MAX=10. What I did at first is try to define an axis between z and x. z=MAX-x was my choice.
And then I preceded to draw this axis for every small increment of x, thus creating the rectangle. This is the code:
anArray = []
for i in range(0, 101, 1):
z = float(i)/10
#print "x: ", x
y = 10 - z
#print "y: ", y
for a in range(0, 101, 1):
anArray.append([float(a)/10, y, z])
#endfor
#endfor
verts = np.array(anArray)
ax.plot(verts[:,0],verts[:,1],verts[:,2], zdir='y')
精彩评论