简体   繁体   English

同一图上的多个对象(MATPLOTLIB)

[英]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))

Box(3,1,3,[0,1,0],np.eye(3)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.

相关问题 MatPlotLib:同一散点图上的多个数据集 - MatPlotLib: Multiple datasets on the same scatter plot 如何在 Matplotlib 中在同一个图形上绘制多个函数? - How to plot multiple functions on the same figure, in Matplotlib? 如何使用 matplotlib 在同一图上绘制多个轨迹 - How to plot multiple trajectories on same plot using matplotlib 如何使用matplotlib在同一图上绘制多个动画函数? - how to plot multiple animated functions on the same plot with matplotlib? 将 matplotlib 绘图对象分配给 _ - assigning matplotlib plot objects to _ Matplotlib:当同一类中的不同函数调用绘图例程时,在同一绘图上绘制多个图吗? - Matplotlib: plot multiple graphs on the same plot when different functions in the same class call the plot routine? 如何在matplotlib中从同一文本文件绘制多组数据 - How to plot multiple set of data from same text file in matplotlib matplotlib.pyplot.plotfile()-如何将多个图形绘制到同一图形中? - matplotlib.pyplot.plotfile() - How to plot multiple graphs into same figure? Python和Matplotlib:在同一图形上快速绘制多个图形 - Python and Matplotlib: Plot multiple graphs on the same figure fast 如何使用matplotlib在同一行中绘制多个图形? - How can I plot multiple figure in the same line with matplotlib?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM