[英]multiple objects on the same plot (MATPLOTLIB)
SHORT QUESTION: I'd like to draw different shapes using winged egde strucutre, so I have one class that actually draw any winged eged and another to define a cube and other shapes. 简短的问题:我想使用有翼的egde strucutre绘制不同的形状,所以我有一类实际绘制任何有翼的eged,另一类定义了立方体和其他形状。 Now I want to draw 2 cubes on the same figure but I can't and I always get one cube in each figure.
现在,我想在同一图形上绘制2个多维数据集,但是我不能,而且我总是在每个图形中得到一个多维数据集。
LONG QUESTION: I'd like to draw different shapes using winged egde strucutre, so I have: 长问:我想用有翼的egde strucutre绘制不同的形状,所以我有:
class WEdge -> wedge_instance = WEdge(vertices, faces)
and then I have one class for each shape that I need to draw for example: 然后我需要为每个形状绘制一个类,例如:
class Box -> simplebox = Box(vertices, faces, translation, rotation)
In the WEdge class I actually plot the objects using the following code: 在WEdge类中,我实际上使用以下代码绘制对象:
ax = a3.Axes3D(pl.figure())
for k in range(self.nFaces):
currentColumn = self.faces[k,:]
vtx = np.zeros([4,3])
j = 0
for i in currentColumn:
vtx[j] = self.vertices[i-1]
j = j +1
tri = a3.art3d.Poly3DCollection([vtx])
tri.set_color(colors.rgb2hex(sp.rand(3)))
tri.set_edgecolor('b')
ax.add_collection3d(tri)
The problem is when I want to draw two cube in the same figure. 问题是当我想在同一图中绘制两个立方体时。 I have tried many possible combinations of hold, gca and so on but in the end I get always one cube in Figure 1 and the other in Figure 2.
我尝试了hold,gca等的许多可能组合,但最后我总是在图1中得到一个多维数据集,在图2中得到另一个多维数据集。
Example: 例:
>>>Box(3,1,3, [0,1,0], np.eye(3))
>>> # hold, gca, timer...
>>>Box(3,1,3, [1,0,3], np.eye(3))
Don't define a new axis for each "structure": 不要为每个“结构”定义新的轴:
ax = a3.Axes3D(pl.figure())
Pass ax
into the WEdge
class, so they can all draw on the same axis: 将
ax
传递到WEdge
类中,以便它们都可以在同一轴上绘制:
def init(self, ..., ax=None):
self.ax = ax if ax else a3.Axes3D(pl.figure())
we1 = WEdge()
we2 = WEdge(ax=we1.ax)
or perhaps more egalitarian, 或更平等的
ax = a3.Axes3D(pl.figure())
we1 = WEdge(ax)
we2 = WEdge(ax)
You may need to also pass ax
to your cube class too. 您可能还需要将
ax
传递给多维数据集类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.