Matplotlib 3D 轴中的 2D 多边形
我使用 matplotlib 将一些数据绘制为 3D 轴中的 2D 曲线。我使用 ax =axes3d.Axes3D() 来定义我的轴,并使用 ax.plot(x, y, zs='z') 来绘制我的 2D 曲线3D空间。
现在我想添加一些看起来像此页面上的内容 http://matplotlib.sourceforge .net/examples/mplot3d/polys3d_demo.html,但我想直接输入顶点的坐标。在此示例中,他们有一个固定的 z
数组,并绘制带有顶点 (x,y)
的多边形,而我想要的是 z(x)
> 和 (x,y)
顶点。有谁知道如何做这样的事情?
实际上我不需要集合的东西,我只想在任意方向上绘制一个大正方形。
我尝试简单地输入坐标并使用 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')
它确实绘制了一个正方形,但我无法(或不知道如何)填充脸部。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望这就是你想要的!
我的矩形将从 0 到 10。所以 MAX=10。
我首先做的是尝试定义 z 和 x 之间的轴。
z=MAX-x 是我的选择。
然后我开始为 x 的每个小增量绘制该轴,从而创建矩形。
这是代码:
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: